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

Environment variables are not injected in parent matrix job

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • envinject-plugin
    • None
    • Jenkins 1.485 on RHEL5 x86_64, envinject 1.72

      When I choose to prepare environment for the run and provide properties content, these are not injected in matrix parent project. This behavior causes SCM checkout to fail, since variables are required in Clearcase config spec.

          [JENKINS-15507] Environment variables are not injected in parent matrix job

          With a matrix job, by default for a SCM checkout, this step is exectued:

          • at job level (before each axe)
          • for each axe
            All source code are gathered in a single directory: the workspace

          Can you confirm it the same behaviour for the Clearcase Jenkins plugin?

          EnvInject variables are only injected at the moment for each axe.
          Therefore, you're right there is an issue.

          Gregory Boissinot added a comment - With a matrix job, by default for a SCM checkout, this step is exectued: at job level (before each axe) for each axe All source code are gathered in a single directory: the workspace Can you confirm it the same behaviour for the Clearcase Jenkins plugin? EnvInject variables are only injected at the moment for each axe. Therefore, you're right there is an issue.

          Code changed in jenkins
          User: Gregory Boissinot
          Path:
          src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java
          http://jenkins-ci.org/commit/envinject-plugin/d196214e3aa9c739b7a15e25a19537a72ea1d0f1
          Log:
          Proposal to JENKINS-15507

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Gregory Boissinot Path: src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java http://jenkins-ci.org/commit/envinject-plugin/d196214e3aa9c739b7a15e25a19537a72ea1d0f1 Log: Proposal to JENKINS-15507

          I don't know why I previously excluded the environment injection at the matrix job level.
          However, I added it.
          Please could you check if this new version suit you (about an official release)?
          The snapshot version can be found here:
          https://buildhive.cloudbees.com/job/jenkinsci/job/envinject-plugin/59/org.jenkins-ci.plugins$envinject/

          Gregory Boissinot added a comment - I don't know why I previously excluded the environment injection at the matrix job level. However, I added it. Please could you check if this new version suit you (about an official release)? The snapshot version can be found here: https://buildhive.cloudbees.com/job/jenkinsci/job/envinject-plugin/59/org.jenkins-ci.plugins$envinject/

          Can you please share when new version of envinject with this fixed issue will be realease officially!!!

          hiteswar kumar added a comment - Can you please share when new version of envinject with this fixed issue will be realease officially!!!

          Available from EnvInject 1.73

          Gregory Boissinot added a comment - Available from EnvInject 1.73

          S Stack added a comment - - edited

          Reopening/Bug seen in 1.73 - 1.88

          • We've been stuck at EnvInject version 1.72 for the past year.
          • Using SharedObjects 0.44
          • Using Rebuilder 1.20

          Simple usage scenario to recreate bug

          • Create a matrix job with one user-defined axis named SERVICE_NAME; values are A B C
            • check : Run each configuration sequentially
          • Rebuild settings
            • check: Prepare an environment for run
            • check: Keep Jenkins env var's
            • check: Keep Jenkins build var's
            • Evaluated Groovy script
              def env = [:]
              if ( SERVICE_NAME == 'C' ) {
                 env = ["ADDITIONAL_SETTINGS" : " xyz " ];
              } else {
                 env = ["ADDITIONAL_SETTINGS" : "" ];
              }
              

          Results

          1.72
          • Each axis job runs successfully
          • Example log for SERVICE_NAME = C
            Started by upstream project "test-JENKINS-15507" build number 1
            originally caused by:
             Started by user sstack
            [EnvInject] - Loading node environment variables.
            [EnvInject] - Preparing an environment for the build.
            [EnvInject] - Keeping Jenkins system variables.
            [EnvInject] - Keeping Jenkins build variables.
            [EnvInject] - Adding build parameters as variables.
            [EnvInject] - Evaluation the following Groovy script content: 
            def env = [:]
            if (SERVICE_NAME == 'C') {
               env = ["ADDITIONAL_SETTINGS" : " xyz "];
            } else {
               env = ["ADDITIONAL_SETTINGS" : ""];
            }
            return env;
            
            [EnvInject] - Injecting contributions.
            Building in workspace /var/opt/jenkins-data/jobs/test-JENKINS-15507/workspace/SERVICE_NAME/C
            [C] $ /usr/bin/env bash /var/tmp/jenkins/hudson8185538443495220535.sh
            
          1.73 and later
          • Parent matrix job fails and thus no axis children jobs are executed.
            Started by user sstack
            [EnvInject] - Loading node environment variables.
            [EnvInject] - Preparing an environment for the build.
            [EnvInject] - Keeping Jenkins system variables.
            [EnvInject] - Keeping Jenkins build variables.
            [EnvInject] - Evaluation the following Groovy script content: 
            def env = [:]
            if (SERVICE_NAME == 'C') {
               env = ["ADDITIONAL_SETTINGS" : " xyz "];
            } else {
               env = ["ADDITIONAL_SETTINGS" : ""];
            }
            return env;
            
            [EnvInject] - [ERROR] - SEVERE ERROR occurs: No such property: SERVICE_NAME for class: Script1
            Finished: FAILURE
            
          • In the failed job above, the Evaluated Groovy Script doesn't recognize the axis value SERVICE_NAME as an exported property/env var.

          S Stack added a comment - - edited Reopening/Bug seen in 1.73 - 1.88 We've been stuck at EnvInject version 1.72 for the past year. Using SharedObjects 0.44 Using Rebuilder 1.20 Simple usage scenario to recreate bug Create a matrix job with one user-defined axis named SERVICE_NAME ; values are A B C check : Run each configuration sequentially Rebuild settings check : Prepare an environment for run check : Keep Jenkins env var's check : Keep Jenkins build var's Evaluated Groovy script def env = [:] if ( SERVICE_NAME == 'C' ) { env = [ "ADDITIONAL_SETTINGS" : " xyz " ]; } else { env = [ "ADDITIONAL_SETTINGS" : "" ]; } Results 1.72 Each axis job runs successfully Example log for SERVICE_NAME = C Started by upstream project "test-JENKINS-15507" build number 1 originally caused by: Started by user sstack [EnvInject] - Loading node environment variables. [EnvInject] - Preparing an environment for the build. [EnvInject] - Keeping Jenkins system variables. [EnvInject] - Keeping Jenkins build variables. [EnvInject] - Adding build parameters as variables. [EnvInject] - Evaluation the following Groovy script content: def env = [:] if (SERVICE_NAME == 'C' ) { env = [ "ADDITIONAL_SETTINGS" : " xyz " ]; } else { env = [ "ADDITIONAL_SETTINGS" : ""]; } return env; [EnvInject] - Injecting contributions. Building in workspace / var /opt/jenkins-data/jobs/test-JENKINS-15507/workspace/SERVICE_NAME/C [C] $ /usr/bin/env bash / var /tmp/jenkins/hudson8185538443495220535.sh 1.73 and later Parent matrix job fails and thus no axis children jobs are executed. Started by user sstack [EnvInject] - Loading node environment variables. [EnvInject] - Preparing an environment for the build. [EnvInject] - Keeping Jenkins system variables. [EnvInject] - Keeping Jenkins build variables. [EnvInject] - Evaluation the following Groovy script content: def env = [:] if (SERVICE_NAME == 'C' ) { env = [ "ADDITIONAL_SETTINGS" : " xyz " ]; } else { env = [ "ADDITIONAL_SETTINGS" : ""]; } return env; [EnvInject] - [ERROR] - SEVERE ERROR occurs: No such property: SERVICE_NAME for class: Script1 Finished: FAILURE In the failed job above, the Evaluated Groovy Script doesn't recognize the axis value SERVICE_NAME as an exported property/env var.

          Sverre Moe added a comment -

          Is there any progress on this issue? I am unable to use Git Publisher to create a tag with tagname from an environment variable I have injected into the build process.

          Sverre Moe added a comment - Is there any progress on this issue? I am unable to use Git Publisher to create a tag with tagname from an environment variable I have injected into the build process.

          Sverre Moe added a comment -

          Resolution is still Unresolved, but the latest version of this plugin does work (partly). Environment variables defined in "Prepare an environment for the run" are available for matrix parent and all axis. However environment variables defined in "Inject Environment Variables" Build step is not available on matrix parent.

          Sverre Moe added a comment - Resolution is still Unresolved, but the latest version of this plugin does work (partly). Environment variables defined in "Prepare an environment for the run" are available for matrix parent and all axis. However environment variables defined in "Inject Environment Variables" Build step is not available on matrix parent.

          I'm currently facing this issue with Jenkins 1.643 and EnvInject 1.92.1 . I'm happy to provide debugging data if that would be useful.

          Quentin Hartman added a comment - I'm currently facing this issue with Jenkins 1.643 and EnvInject 1.92.1 . I'm happy to provide debugging data if that would be useful.

            gbois Gregory Boissinot
            raspy Krzysztof Malinowski
            Votes:
            6 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: