Bash Script Fails During Jenkins Build But Does Not Fail Locally

I’ve been trying to debug this issue all day with no success.

Issue: Bash script executes successfully locally on a Linux CentOS7 VM (jenkins build agent) but fails during Jenkins build.

Here’s the simple script.

#! /bin/bash
echo "before beyond compare command"
bcompare @"bc_report.ps1" "./Output_Base/<Folder_Name>" "./Output_Compare/<Folder Name>" "Report.html"
echo "after beyond compare command"

The output in the Jenkins build log (for the execution of the script) is just:

before beyond compare command
after beyond compare command

When viewing the VM during the Jenkins build, I’m not seeing an artifact being produced. The user during the Jenkins build is Root, when executing the script locally, I’m also doing so as Root with success.

Dumbing down the script further to just open Beyond Compare, works locally but fails during Jenkins.

Trying a different application such as the basic calculator application, using command “gnome-calculator” also fails during the jenkins build, there error shows as:

(gnome-calculator:17938): Gtk-WARNING **: 18:03:43.470: cannot open display: 

I’m pretty sure this is a Jenkins and/or linux security issue, just can’t seem to figure it out. Anyone seen something similar?

Frequently there are differences between the environment where a program runs and the Jenkins environment. One technique to help identify those differences is to display the environment while the job is running and compare that with the environment on your desktop.

There might also be differences in the program being called on the Jenkins agent and the program on your desktop.

For example

#! /bin/bash
echo "==== Environment"
env | sort
echo "==== Which bcompare"
which bcompare
echo "==== File details of bcompare"
ls -al /usr/bin/bcompare # Assuming the location reported by `which` is `/usr/bin/bcompare`
echo "==== File details of Output_Base"
ls -al Output_Base
echo "==== File details of Output_Compare"
ls -al Output_Compare
echo "before beyond compare command"
bcompare @"bc_report.ps1" "./Output_Base/<Folder_Name>" "./Output_Compare/<Folder Name>" "Report.html"
echo "after beyond compare command"

If the bcompare program requires a display device, you’ll need to define a display device that the Jenkins job can use. You could grant the Jenkins job access to your display device by reducing permissions on the display device and defining the correct environment variables to allow the job to access it. A more typical solution is to install a Jenkins plugin that creates a display device for the duration of the job. The Xvfb and Xvnc plugins both provide a display device for the duration of a build.

1 Like