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

Re-defining existing job loses environment variables

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Cannot Reproduce
    • Component/s: job-dsl-plugin
    • Labels:
      None
    • Environment:
      EnvInject 2.1.5
      Job DSL 1.69
      Jenkins 2.107.2
    • Similar Issues:

      Description

      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>
        

        Attachments

          Issue Links

            Activity

            Hide
            aarondmarasco_vsi 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.

            Show
            aarondmarasco_vsi 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.
            Hide
            daspilker 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.

            Show
            daspilker 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.
            Hide
            aarondmarasco_vsi 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!

            Show
            aarondmarasco_vsi 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!

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: