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

Environment variables aren't passed to the docker container anymore

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • Jenkins Version: 1.609.1
      Plugin Version: 1.5.1 (previously installed version was 1.3)

      The environment variables of the host system aren't passed to the docker container anymore. This behaviour has changed since the last updates of the plugin, because it worked in a previous version.

      Example output with plugin version 1.3:

      [sbs-admin-trunk] $ docker exec --tty 22f4b8d78b817a1cf73d0e5ab48cab31d65de4b3b2db01d1388e809a135cd36e /bin/sh -xe /tmp/hudson7758699465236749562.sh
      + env
      JENKINS_HOME=/export/sbs/jenkins/home
      USER=jenkins
      HOSTNAME=22f4b8d78b81
      GIT_COMMIT=21c329e0976c10e935e3ad33b60fa0b3e446b581
      LD_LIBRARY_PATH=/export/build/sbs/packages/linux/svn-1.7/lib:
      NODE_LABELS=64bit android-sdk berlin cloud docker linux linux-cloud-078 ubuntu ubuntu-14.04
      HOME=/home/jenkins
      PATH+JDK=/export/build/jenkins-localfs/tools/hudson.model.JDK/jdk-1.7.0_latest_/bin
      JENKINS_SERVER_COOKIE=132c0177868555ac
      WORKSPACE=/export/build/jenkins-localfs/workspace/sbs-admin-trunk
      LOGNAME=jenkins
      NODE_NAME=linux-cloud-078
      TERM=xterm
      HUDSON_HOME=/export/sbs/jenkins/home
      PATH=/export/build/sbs/packages/linux/svn-1.7/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
      BUILD_ID=29
      BUILD_TAG=jenkins-sbs-admin-trunk-29
      JENKINS_URL=https://...
      GIT_URL=https://...
      JOB_URL=https://...
      BUILD_NUMBER=29
      SHELL=/bin/bash
      JOB_NAME=sbs-admin-trunk
      JAVA_HOME=/export/build/jenkins-localfs/tools/hudson.model.JDK/jdk-1.7.0_latest_
      PWD=/export/build/jenkins-localfs/workspace/sbs-admin-trunk
      GIT_PREVIOUS_COMMIT=21c329e0976c10e935e3ad33b60fa0b3e446b581
      (and some more...)
      [sbs-admin-trunk] $ docker exec --tty 22f4b8d78b817a1cf73d0e5ab48cab31d65de4b3b2db01d1388e809a135cd36e /export/build/jenkins-localfs/tools/hudson.tasks.Maven_MavenInstallation/maven-3.2.x/bin/mvn -f pom.xml -U -e install -DskipTests
      exec: "/export/build/jenkins-localfs/tools/hudson.tasks.Maven_MavenInstallation/maven-3.2.x/bin/mvn": stat /export/build/jenkins-localfs/tools/hudson.tasks.Maven_MavenInstallation/maven-3.2.x/bin/mvn: no such file or directory
      Build step 'Invoke top-level Maven targets' marked build as failure
      Stopping Docker container after build completion
      

      The same job execution with plugin version 1.5.1:

      [sbs-admin-trunk] $ docker exec --tty --user 5003: ded99d09fec98ff198d27c448abd03fe68eb3f62dca060ee4f23285c21513f91 /bin/sh -xe /tmp/hudson5039313317665547776.sh
      + env
      HOSTNAME=ded99d09fec9
      HOME=/
      TERM=xterm
      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      PWD=/export/build/jenkins-localfs/workspace/sbs-admin-trunk
      [sbs-admin-trunk] $ docker exec --tty --user 5003: ded99d09fec98ff198d27c448abd03fe68eb3f62dca060ee4f23285c21513f91 /export/build/jenkins-localfs/tools/hudson.tasks.Maven_MavenInstallation/maven-3.2.x/bin/mvn -f pom.xml -U -e install -DskipTests
      Error: JAVA_HOME is not defined correctly.
        We cannot execute 
      Build step 'Invoke top-level Maven targets' marked build as failure
      Stopping Docker container after build completion
      

      As you can see, the environment parameters aren't set within the docker container anymore. This influences jobs that rely on specific environment settings as well as the auto installation mechanism of jenkins that uses environment variables in order to set the path of the specified tool versions (for example JAVA_HOME).

          [JENKINS-30113] Environment variables aren't passed to the docker container anymore

          Evan Powell added a comment -

          It looks like the code that adds "--env ..." to the `docker run` command has been commented out. This appears to be accidental during development I suspect.

          The offending comments:

          https://github.com/jenkinsci/docker-custom-build-environment-plugin/commit/8bcb202a7b83a131894cad802ea98748f94e13fb#diff-cde88d8baffd43e1d6957025fa4e5f8eR166

          Evan Powell added a comment - It looks like the code that adds "--env ..." to the `docker run` command has been commented out. This appears to be accidental during development I suspect. The offending comments: https://github.com/jenkinsci/docker-custom-build-environment-plugin/commit/8bcb202a7b83a131894cad802ea98748f94e13fb#diff-cde88d8baffd43e1d6957025fa4e5f8eR166

          Evan Powell added a comment -

          I have opened a PR for this issue: https://github.com/jenkinsci/docker-custom-build-environment-plugin/pull/29

          This works for me on Jenkins 1.609.2.

          Evan Powell added a comment - I have opened a PR for this issue: https://github.com/jenkinsci/docker-custom-build-environment-plugin/pull/29 This works for me on Jenkins 1.609.2.

          It's not just by accident. Docker container should not inherit the full slave env (PATH for sample can be fully irrelevant)
          Need to build a custom env map using various env sources (scm, build parameters, build actions...).

          Nicolas De Loof added a comment - It's not just by accident. Docker container should not inherit the full slave env (PATH for sample can be fully irrelevant) Need to build a custom env map using various env sources (scm, build parameters, build actions...).

          Code changed in jenkins
          User: Nicolas De Loof
          Path:
          src/main/java/com/cloudbees/jenkins/plugins/docker_build_env/Docker.java
          src/main/java/com/cloudbees/jenkins/plugins/docker_build_env/DockerBuildWrapper.java
          http://jenkins-ci.org/commit/docker-custom-build-environment-plugin/79e47f51a82cb66bdb44bf0c5b03460edc6f0cbd
          Log:
          JENKINS-30113 configure container with a subset of build environment

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Nicolas De Loof Path: src/main/java/com/cloudbees/jenkins/plugins/docker_build_env/Docker.java src/main/java/com/cloudbees/jenkins/plugins/docker_build_env/DockerBuildWrapper.java http://jenkins-ci.org/commit/docker-custom-build-environment-plugin/79e47f51a82cb66bdb44bf0c5b03460edc6f0cbd Log: JENKINS-30113 configure container with a subset of build environment

          Evan Powell added a comment -

          Certainly a fair point - and some env vars could potentially mess up the execution environment, $PATH included.

          Thanks for the update and the more extensive changeset. I had a mind to try my hand at this today, but you're already on it.

          Evan Powell added a comment - Certainly a fair point - and some env vars could potentially mess up the execution environment, $PATH included. Thanks for the update and the more extensive changeset. I had a mind to try my hand at this today, but you're already on it.

          ryangardner added a comment -

          For my maven job it looks like it's setting an empty CLASSPATH and passing it in - and then breaking the build:

          docker exec --tty --user 0: c2df0f86ce0edc1b537eac22ec4637984f3bc6270ca3d85e2ac3c4a0491e9362 env BUILD_CAUSE=MANUALTRIGGER BUILD_CAUSE_MANUALTRIGGER=true BUILD_CONTAINER_ID=c2df0f86ce0edc1b537eac22ec4637984f3bc6270ca3d85e2ac3c4a0491e9362 BUILD_DISPLAY_NAME=#4 BUILD_ID=4 BUILD_NUMBER=4  ... BUILD_URL=http://foo.server.com:8080/job/dockertest/4/ CLASSPATH= EXECUTOR_NUMBER=0
          

          And then it fails with:

          Exception in thread "main" java.lang.ClassNotFoundException: hudson.remoting.Launcher
          	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
          	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
          	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
          	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
          	at jenkins.maven3.agent.Maven32Main.main(Maven32Main.java:143)
          	at jenkins.maven3.agent.Maven32Main.main(Maven32Main.java:71)
          Stopping Docker container after build completion
          ERROR: Failed to parse POMs
          java.io.EOFException: unexpected stream termination
          	at hudson.remoting.ChannelBuilder.negotiate(ChannelBuilder.java:333)
          	at hudson.remoting.Channel.<init>(Channel.java:435)
          	at hudson.remoting.Channel.<init>(Channel.java:413)
          	at hudson.remoting.Channel.<init>(Channel.java:409)
          	at hudson.remoting.Channel.<init>(Channel.java:397)
          	at hudson.remoting.Channel.<init>(Channel.java:388)
          	at hudson.remoting.Channel.<init>(Channel.java:379)
          	at hudson.maven.AbstractMavenProcessFactory$LinkedChannel.<init>(AbstractMavenProcessFactory.java:272)
          	at hudson.maven.AbstractMavenProcessFactory$LinkedChannel$1.<init>(AbstractMavenProcessFactory.java:292)
          	at hudson.maven.AbstractMavenProcessFactory$LinkedChannel.forProcess(AbstractMavenProcessFactory.java:292)
          	at hudson.maven.AbstractMavenProcessFactory.newProcess(AbstractMavenProcessFactory.java:380)
          	at hudson.maven.ProcessCache.get(ProcessCache.java:236)
          	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:778)
          	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
          	at hudson.model.Run.execute(Run.java:1741)
          	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:531)
          	at hudson.model.ResourceController.execute(ResourceController.java:98)
          	at hudson.model.Executor.run(Executor.java:408)
          

          ryangardner added a comment - For my maven job it looks like it's setting an empty CLASSPATH and passing it in - and then breaking the build: docker exec --tty --user 0: c2df0f86ce0edc1b537eac22ec4637984f3bc6270ca3d85e2ac3c4a0491e9362 env BUILD_CAUSE=MANUALTRIGGER BUILD_CAUSE_MANUALTRIGGER= true BUILD_CONTAINER_ID=c2df0f86ce0edc1b537eac22ec4637984f3bc6270ca3d85e2ac3c4a0491e9362 BUILD_DISPLAY_NAME=#4 BUILD_ID=4 BUILD_NUMBER=4 ... BUILD_URL=http: //foo.server.com:8080/job/dockertest/4/ CLASSPATH= EXECUTOR_NUMBER=0 And then it fails with: Exception in thread "main" java.lang.ClassNotFoundException: hudson.remoting.Launcher at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227) at jenkins.maven3.agent.Maven32Main.main(Maven32Main.java:143) at jenkins.maven3.agent.Maven32Main.main(Maven32Main.java:71) Stopping Docker container after build completion ERROR: Failed to parse POMs java.io.EOFException: unexpected stream termination at hudson.remoting.ChannelBuilder.negotiate(ChannelBuilder.java:333) at hudson.remoting.Channel.<init>(Channel.java:435) at hudson.remoting.Channel.<init>(Channel.java:413) at hudson.remoting.Channel.<init>(Channel.java:409) at hudson.remoting.Channel.<init>(Channel.java:397) at hudson.remoting.Channel.<init>(Channel.java:388) at hudson.remoting.Channel.<init>(Channel.java:379) at hudson.maven.AbstractMavenProcessFactory$LinkedChannel.<init>(AbstractMavenProcessFactory.java:272) at hudson.maven.AbstractMavenProcessFactory$LinkedChannel$1.<init>(AbstractMavenProcessFactory.java:292) at hudson.maven.AbstractMavenProcessFactory$LinkedChannel.forProcess(AbstractMavenProcessFactory.java:292) at hudson.maven.AbstractMavenProcessFactory.newProcess(AbstractMavenProcessFactory.java:380) at hudson.maven.ProcessCache.get(ProcessCache.java:236) at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:778) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537) at hudson.model.Run.execute(Run.java:1741) at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:531) at hudson.model.ResourceController.execute(ResourceController.java:98) at hudson.model.Executor.run(Executor.java:408)

            jonhermansen Jon Hermansen
            emicify Michael Süß
            Votes:
            6 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: