Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-17127

Pass DISPLAY as environment variable to Maven builds

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Cannot Reproduce
    • Component/s: xvfb-plugin
    • Labels:
      None
    • Environment:
      Debian 6.0.3
      Jenkins 1.501
      Xvfb plugin 1.0.7
    • Similar Issues:

      Description

      For a freestyle project with an "Invoke top-level Maven targets" build step and the Xvfb plugin enabled, the display number is not passed in the DISPLAY environment variable, but as a property, instead:

      jenkins@ci4:~$ env|grep DISPLAY
      DISPLAY=:85
      jenkins@ci4:~$ ps -ef|grep firef
      jenkins  31202 22976  0 17:48 ?        00:00:00 /bin/sh /opt/maven3.0.4/bin/mvn -f pom.xml -Dtestsuite=Document -DDISPLAY=:7 clean install -B -Dwebdriver.firefox.bin=/opt/firefox-esr/firefox -Dtest=TestSuiteDocument -Djava.io.tmpdir=/home/jenkins/workspace/selenium-tests/tmp -Dmaven.repo.local=/home/jenkins/workspace/selenium-tests/.repository
      jenkins  31236 31202 19 17:48 ?        00:00:09 /opt/java/bin/java -Djava.io.tmpdir=/tmp/tmp_maven.31202.tmp -Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m -classpath /opt/maven3.0.4/boot/plexus-classworlds-2.4.jar -Dclassworlds.conf=/opt/maven3.0.4/bin/m2.conf -Dmaven.home=/opt/maven3.0.4 org.codehaus.plexus.classworlds.launcher.Launcher -f pom.xml -Dtestsuite=Document -DDISPLAY=:7 clean install -B -Dwebdriver.firefox.bin=/opt/firefox-esr/firefox -Dtest=TestSuiteDocument -Djava.io.tmpdir=/home/jenkins/workspace/selenium-tests/tmp -Dmaven.repo.local=/home/jenkins/workspace/selenium-tests/.repository
      jenkins  31375 31323 40 17:49 ?        00:00:16 /opt/firefox-esr/firefox -foreground
      jenkins  31416 27994  0 17:49 pts/0    00:00:00 grep firef
      jenkins@ci4:~$ sed -e 's/.*DISPLAY=//' /proc/31375/environ
      :85...
      

      Outside of the build, the DISPLAY variable is set to :85, Jenkins passes -DDISPLAY=:7 to Maven, but the firefox process still has DISPLAY=:85 in its environment.

      If we convert our build step to "Execute shell", everything works as expected but then we have to "hard-code" the Maven version instead of choosing one from the Maven installations that we configured globally.

      Would it be hard to change the behaviour so that the DISPLAY environment variable gets set instead, or in addition to the Java property?

        Attachments

          Activity

          Hide
          zregvart zregvart added a comment -

          Hi Uwe, are you certain that jenkins started the firefox process? From what I see in your example output parent process of the firefox process has PID 31323, whilst maven/java processes have PID 31236 and 31202.

          DISPLAY environment variable should be set in all processes started by the jenkins job, even in the ones started by "Invoke top-level Maven targets". You can check this with exec-maven-plugin, i.e.:

          <?xml version="1.0" encoding="UTF-8"?>
          <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
             <modelVersion>4.0.0</modelVersion>
             <groupId>freestyle</groupId>
             <artifactId>sample</artifactId>
             <packaging>jar</packaging>
             <version>1.0.0-SNAPSHOT</version>
             <build>
                <plugins>
                   <plugin>
                      <groupId>org.codehaus.mojo</groupId>
                      <artifactId>exec-maven-plugin</artifactId>
                      <version>1.2.1</version>
                      <executions>
                         <execution>
                            <id>show-display</id>
                            <phase>compile</phase>
                            <goals>
                               <goal>exec</goal>
                            </goals>
                            <configuration>
                               <executable>env</executable>
                            </configuration>
                         </execution>
                      </executions>
                   </plugin>
                </plugins>
             </build>
          </project>
          
          Show
          zregvart zregvart added a comment - Hi Uwe, are you certain that jenkins started the firefox process? From what I see in your example output parent process of the firefox process has PID 31323, whilst maven/java processes have PID 31236 and 31202. DISPLAY environment variable should be set in all processes started by the jenkins job, even in the ones started by "Invoke top-level Maven targets". You can check this with exec-maven-plugin, i.e.: <?xml version= "1.0" encoding= "UTF-8" ?> <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelVersion> 4.0.0 </modelVersion> <groupId> freestyle </groupId> <artifactId> sample </artifactId> <packaging> jar </packaging> <version> 1.0.0-SNAPSHOT </version> <build> <plugins> <plugin> <groupId> org.codehaus.mojo </groupId> <artifactId> exec-maven-plugin </artifactId> <version> 1.2.1 </version> <executions> <execution> <id> show-display </id> <phase> compile </phase> <goals> <goal> exec </goal> </goals> <configuration> <executable> env </executable> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
          Hide
          ustuehler Uwe Stuehler added a comment -

          Thank you for the helpful code snippet! It turns out that we were a little overeager in making sure that all processes started as jenkins get the same environment. The DISPLAY variable was set in all of /.profile, /.bash_profile and ~/.bashrc. The Xvfb plugin works fine.

          Show
          ustuehler Uwe Stuehler added a comment - Thank you for the helpful code snippet! It turns out that we were a little overeager in making sure that all processes started as jenkins get the same environment. The DISPLAY variable was set in all of /.profile , /.bash_profile and ~/.bashrc . The Xvfb plugin works fine.
          Hide
          marc_guenther Marc Günther added a comment -

          Unfortunately, that's not entirely true. When a DISPLAY variable already exists in the environment of the slave, the plugin will overwrite it with the correct value in a "Execute shell" build step, but it will NOT overwrite it in a "Invoke Maven" build stop.

          I verified that the xvfb plugin actually changes the DISPLAY entry in the EnvVars map, but it seems the Maven build step changes it back later. Although looking at the source code, I can not find where it does that.

          I'm not sure if this really is a bug with this plugin, or with Jenkins Maven build step, as the plugin seems to do the right thing.

          Show
          marc_guenther Marc Günther added a comment - Unfortunately, that's not entirely true. When a DISPLAY variable already exists in the environment of the slave, the plugin will overwrite it with the correct value in a "Execute shell" build step, but it will NOT overwrite it in a "Invoke Maven" build stop. I verified that the xvfb plugin actually changes the DISPLAY entry in the EnvVars map, but it seems the Maven build step changes it back later. Although looking at the source code, I can not find where it does that. I'm not sure if this really is a bug with this plugin, or with Jenkins Maven build step, as the plugin seems to do the right thing.
          Hide
          zregvart zregvart added a comment -

          Hi Marc, can you provide a test scenario for the problem you're experiencing? As I wrote in the previous comment, to me it seems that when Invoke Maven command is performed in freestyle build, DISPLAY is set correctly regardless of it being set in the environment of the process tree or not. I.e. my setup has DISPLAY variable set (I'm running in GUI mode), so when I start jenkins it inherits DISPLAY from my GUI enviroment, and the POM above and with Invoke Maven step on freestyle projects yields the Xvfb DISPLAY opened by the plugin.

          Show
          zregvart zregvart added a comment - Hi Marc, can you provide a test scenario for the problem you're experiencing? As I wrote in the previous comment, to me it seems that when Invoke Maven command is performed in freestyle build, DISPLAY is set correctly regardless of it being set in the environment of the process tree or not. I.e. my setup has DISPLAY variable set (I'm running in GUI mode), so when I start jenkins it inherits DISPLAY from my GUI enviroment, and the POM above and with Invoke Maven step on freestyle projects yields the Xvfb DISPLAY opened by the plugin.
          Hide
          marc_guenther Marc Günther added a comment -

          I was using your pom.xml from above. I created a freestyle job, with two buildsteps, a shell which executes mvn and a Maven buildstep doing the same. I get the correct output from the shell build step, and the wrong output from the other.

          Maybe the important point is, that the DISPLAY variable has to exist in the environment of the slave (we are using swarm) and not the master?

          Show
          marc_guenther Marc Günther added a comment - I was using your pom.xml from above. I created a freestyle job, with two buildsteps, a shell which executes mvn and a Maven buildstep doing the same. I get the correct output from the shell build step, and the wrong output from the other. Maybe the important point is, that the DISPLAY variable has to exist in the environment of the slave (we are using swarm) and not the master?
          Hide
          zregvart zregvart added a comment -

          Still no way given to reproduce this issue, and original submitter confirmed that the DISPLAY was set externally. Closing.

          Show
          zregvart zregvart added a comment - Still no way given to reproduce this issue, and original submitter confirmed that the DISPLAY was set externally. Closing.
          Hide
          zregvart zregvart added a comment -

          Closing resloved issues

          Show
          zregvart zregvart added a comment - Closing resloved issues
          Hide
          marc_guenther Marc Günther added a comment -

          As this is a different problem from the original report, I created a separate ticket with steps to reproduce: JENKINS-19950

          Show
          marc_guenther Marc Günther added a comment - As this is a different problem from the original report, I created a separate ticket with steps to reproduce: JENKINS-19950

            People

            Assignee:
            zregvart zregvart
            Reporter:
            ustuehler Uwe Stuehler
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: