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

EnvInject plugin using a cached value for ${WORKSPACE}

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • envinject-plugin
    • None

      Starting yesterday, the EnvInject plugin seems to suddenly start using a cached value for ${WORKSPACE}. We have the following value in "Properties Content" under "Inject environment variables to the build process":

      PATH=${WORKSPACE}/.env/bin:$PATH

      When working properly, in the console output this appears as:

      [EnvInject] - Injecting as environment variables the properties content
      PATH=${WORKSPACE}/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin

      Over the past couple of days this has suddenly started appearing as:

      [EnvInject] - Injecting as environment variables the properties content
      PATH=/Users/Shared/Jenkins/Home/jobs/bidpom.stage/workspace/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin

      Which is using a workspace path from another job. This causes this job, and all other jobs, to fail. If I restart Jenkins the problem goes away, for awhile, but at some point that exact same path starts getting used by the EnvInject plugin again. This cycle has happened 4 times over the past couple of days, where jobs will run fine for awhile and then suddenly start failing because the path injected changes from:

      ${WORKSPACE}/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin

      to:

      /Users/Shared/Jenkins/Home/jobs/bidpom.stage/workspace/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin

      When this first happened we downgraded the plugin from 1.78 to 1.77 but this hasn't addressed the problem.

      Any help anyone can provide would be greatly appreciated.

          [JENKINS-16233] EnvInject plugin using a cached value for ${WORKSPACE}

          Bob Silverberg created issue -

          This problem went away for about a week after rebooting a few times but just cropped up again. Any help that anyone can provide would be greatly appreciated.

          Bob Silverberg added a comment - This problem went away for about a week after rebooting a few times but just cropped up again. Any help that anyone can provide would be greatly appreciated.

          Dave Hunt added a comment -

          I suspect this is related to JENKINS-15658

          Dave Hunt added a comment - I suspect this is related to JENKINS-15658

          JENKINS-15658 was introduced in version 1.73. Therefore, if it is the cause, you have to downgrade to 1.72.
          For this issue, it seems not to be a workspace from another job but a shared workspace.
          Does this value is specified in another place in the job or in the global configuration?

          Gregory Boissinot added a comment - JENKINS-15658 was introduced in version 1.73. Therefore, if it is the cause, you have to downgrade to 1.72. For this issue, it seems not to be a workspace from another job but a shared workspace. Does this value is specified in another place in the job or in the global configuration?
          Gregory Boissinot made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]

          Hi,
          could you check your job configuration?
          Thanks

          Gregory Boissinot added a comment - Hi, could you check your job configuration? Thanks

          The value is not specified anywhere else in the job nor in the global configuration. It seems to be caching the workspace value that was used for a previous job.

          Bob Silverberg added a comment - The value is not specified anywhere else in the job nor in the global configuration. It seems to be caching the workspace value that was used for a previous job.

          Dave Hunt added a comment -

          This is happening right now. We need to restart Jenkins to fix this, but it will no doubt happen again. I've done a little investigation and found that echoing ${WORKSPACE} in a build shell shows the correct value, but EnvInject has injected the wrong value:

          [CHECKED] Inject environment variables to the build process
          Properties Content:
          TEST=${WORKSPACE}
          PATH=${WORKSPACE}/.env/bin:$PATH

          Execute shell:
          printenv
          echo ${WORKSPACE}
          echo ${PATH}

          Console output:
          ...
          [EnvInject] - Executing scripts and injecting environment variables after the SCM step.
          [EnvInject] - Injecting as environment variables the properties content
          TEST=/Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace
          PATH=/Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
          [EnvInject] - Variables injected successfully.
          ...
          + printenv
          ...
          TEST=/Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace
          WORKSPACE=/Users/Shared/Jenkins/Home/jobs/bouncer.prod/workspace
          PATH=/Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
          ...
          + echo /Users/Shared/Jenkins/Home/jobs/bouncer.prod/workspace
          /Users/Shared/Jenkins/Home/jobs/bouncer.prod/workspace
          + echo /Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
          /Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

          So you can see that WORKSPACE is accurate according to Jenkins environment variables, but EnvInject is expanding it to an incorrect value.

          Please let me know if there's any additional information that would be useful for the next time this fails.

          Dave Hunt added a comment - This is happening right now. We need to restart Jenkins to fix this, but it will no doubt happen again. I've done a little investigation and found that echoing ${WORKSPACE} in a build shell shows the correct value, but EnvInject has injected the wrong value: [CHECKED] Inject environment variables to the build process Properties Content: TEST=${WORKSPACE} PATH=${WORKSPACE}/.env/bin:$PATH Execute shell: printenv echo ${WORKSPACE} echo ${PATH} Console output: ... [EnvInject] - Executing scripts and injecting environment variables after the SCM step. [EnvInject] - Injecting as environment variables the properties content TEST=/Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace PATH=/Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin [EnvInject] - Variables injected successfully. ... + printenv ... TEST=/Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace WORKSPACE=/Users/Shared/Jenkins/Home/jobs/bouncer.prod/workspace PATH=/Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin ... + echo /Users/Shared/Jenkins/Home/jobs/bouncer.prod/workspace /Users/Shared/Jenkins/Home/jobs/bouncer.prod/workspace + echo /Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin /Users/Shared/Jenkins/Home/jobs/bidpom.stage.saucelabs/workspace/.env/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin So you can see that WORKSPACE is accurate according to Jenkins environment variables, but EnvInject is expanding it to an incorrect value. Please let me know if there's any additional information that would be useful for the next time this fails.

          Does '/Users/Shared/Jenkins/Home/jobs/bouncer.prod/workspace' match a specific slave where the build run?

          Gregory Boissinot added a comment - Does '/Users/Shared/Jenkins/Home/jobs/bouncer.prod/workspace' match a specific slave where the build run?

          Code changed in jenkins
          User: Gregory Boissinot
          Path:
          src/main/java/org/jenkinsci/plugins/envinject/EnvInjectBuildWrapper.java
          src/main/java/org/jenkinsci/plugins/envinject/EnvInjectBuilder.java
          src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java
          src/test/java/org/jenkinsci/plugins/envinject/GlobalPropertiesTest.java
          http://jenkins-ci.org/commit/envinject-plugin/23a7086f231e0647bfc24daceacaa1f078f5aa7f
          Log:
          Fix JENKINS-16233

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Gregory Boissinot Path: src/main/java/org/jenkinsci/plugins/envinject/EnvInjectBuildWrapper.java src/main/java/org/jenkinsci/plugins/envinject/EnvInjectBuilder.java src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java src/test/java/org/jenkinsci/plugins/envinject/GlobalPropertiesTest.java http://jenkins-ci.org/commit/envinject-plugin/23a7086f231e0647bfc24daceacaa1f078f5aa7f Log: Fix JENKINS-16233

            gbois Gregory Boissinot
            bobsilverberg Bob Silverberg
            Votes:
            6 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: