0
votes

The job seeder creates a pipeline job and sets environment variable using job dsl as shown below, this pipeline job triggers another job(say job2) which in turn triggers another job(say job3). I want the environment variable set in seed job to be accessed in the triggered jobs.

pipelineJob("job1"){
  description("job1..")
  concurrentBuild(false)
  environmentVariables(
         globalEnv + [TEMP_ENV1               : 'true',
                      TEMP_ENV2               : 'true'
                     ]
   )
  definition {
      cps {
         script(
               """
job1script()
"""
         )
      }
   }
}

I want to access TEMP_ENV1 and TEMP_ENV2 in job3, but both are null in this job. i have a check in script which job3 executes it and it fails, e.g. if (env.TEMP_ENV1) { }

1

1 Answers

0
votes

You should invoke the job using the build step (https://jenkins.io/doc/pipeline/steps/pipeline-build-step/) and pass these along as parameters:

build(
    job: "myjob2", 
    parameters: [
        string(name: 'TEMP_ENV1', defaultValue: TEMP_ENV1, description: 'Temp env var 1')
    ], 
    propagate: false
)