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

Re-defining existing job loses environment variables

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Major Major
    • job-dsl-plugin
    • None
    • EnvInject 2.1.5
      Job DSL 1.69
      Jenkins 2.107.2

      If I define a pipeline job with environment variables in it, on the second (and subsequent) runs, the environment disappears.

      def my_job = pipelineJob("/${ROOT}/${BRANCH_FOLDER}/${pf}/${test}")
      my_job.with {
        description "${test} on ${pf} (${BRANCH_FOLDER})".replaceAll('_', ' ')
        displayName test.replaceAll('_', ' ')
        definition {
            cps {
                script(readFileFromWorkspace('jenkins/runtime/groovy/Jenkinsfile_example_job_to_run.groovy'))
                sandbox()
            }
        }
        environmentVariables {
          envs(
            Upstream_Job_Name: JOB_NAME,
            Upstream_Job_Build: BUILD_NUMBER,
            GIT_BRANCH: BRANCH_FOLDER,
            PLATFORM: pf,
            COMPONENT_TO_TEST: test,
            )
            keepBuildVariables(true)
        }
        quietPeriod 1 // 1 second
      } // my_job
      
      // Launch it!
      queue(my_job) // should be able to be a string too
      
      1. Delete the job
      2. Run the job
      3. Save off target job's config.xml on server
      4. Run the seed job again
      5. Compare on the server:
        $ diff -u ./jobs/Test_Results/jobs/branchname/jobs/pform/jobs/mytest/config.xml /tmp/mytest_good.xml
        --- ./jobs/Test_Results/jobs/branchname/jobs/pform/jobs/mytest/config.xml        2018-04-27 14:52:08.569820997 -0400
        +++ /tmp/mytest_good.xml        2018-04-27 14:51:46.503906858 -0400
        @@ -5,6 +5,21 @@
           <displayName>mytest</displayName>
           <keepDependencies>false</keepDependencies>
           <properties>
        +    <EnvInjectJobProperty plugin="envinject@2.1.5">
        +      <info>
        +        <propertiesContent>Upstream_Job_Name=seed_job
        +Upstream_Job_Build=156
        +GIT_BRANCH=branchname
        +HDL_PLATFORM=pform
        +COMPONENT_TO_TEST=mytest</propertiesContent>
        +        <loadFilesFromMaster>false</loadFilesFromMaster>
        +      </info>
        +      <on>true</on>
        +      <keepJenkinsSystemVariables>true</keepJenkinsSystemVariables>
        +      <keepBuildVariables>true</keepBuildVariables>
        +      <overrideBuildParameters>false</overrideBuildParameters>
        +      <contributors/>
        +    </EnvInjectJobProperty>
             <jenkins.model.BuildDiscarderProperty>
               <strategy class="hudson.tasks.LogRotator">
                 <daysToKeep>-1</daysToKeep>
        

          [JENKINS-51038] Re-defining existing job loses environment variables

          Since the queue command doesn't seem to be designed to pass parameters, with this not working, I'm running out of ideas on how to have a Job DSL launcher for a pipeline job work.

          Aaron D. Marasco added a comment - Since the queue command doesn't seem to be designed to pass parameters, with this not working, I'm running out of ideas on how to have a Job DSL launcher for a pipeline job work.

          I can not reproduce this issue with the following script:

          pipelineJob('example-pipeline') {
            definition {
                cps {
                    script('print "Hello"')
                    sandbox()
                }
            }
            environmentVariables {
              envs(FOO: 'bar')
              keepBuildVariables(true)
            }
          }
          
          queue('example-pipeline')
          

          I am running Jenkins 2.73.3 with Job DSL 1.69, Environment Injector Plugin 2.1.5 and Pipeline Job 2.21.

          Daniel Spilker added a comment - I can not reproduce this issue with the following script: pipelineJob( 'example-pipeline' ) {   definition {       cps {           script( 'print "Hello" ' )           sandbox()       }   }   environmentVariables {     envs(FOO: 'bar' )     keepBuildVariables( true )   } } queue( 'example-pipeline' ) I am running Jenkins 2.73.3 with Job DSL 1.69, Environment Injector Plugin 2.1.5 and Pipeline Job 2.21.

          I just stumbled on JENKINS-43758 and am 99% sure this is what was biting me in this bug report!

          Aaron D. Marasco added a comment - I just stumbled on JENKINS-43758 and am 99% sure this is what was biting me in this bug report!

            daspilker Daniel Spilker
            aarondmarasco_vsi Aaron D. Marasco
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: