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

Re-defining existing job loses environment variables

XMLWordPrintable

    • 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>
        

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

              Created:
              Updated:
              Resolved: