0

I have a situation where the build number of one job has to be passed to another job and the next job will use that as a parameter.

 stages { stage('Build Job1') { steps { script { build job: "001_job" $build_001= env.BUILD_NUMBER of 001_job echo env.BUILD_NUMBER //this echos the build number of this job and not 001_job } } } stage('job_002') { steps { script { build job: "job_002", parameters: [string(name: "${PAYLOAD_PARAM}", value: "$build_001")] } } } } } 

1 Answer 1

1

I figured out a way to do this. Need to have a global environment variable and then assign the build number via funtion like in solution below:

pipeline { environment { BUILD_NUM = '' } agent { label 'master' } stages { stage('Build Job1') { steps { script { def build job: "001_job" def build_num1 = build_job.getNumber() BUILD_NUM = "${build_num1}" echo BUILD_NUM //build number of oo1/job } } } stage('job_002') { steps { script { build job: "job_002", parameters: [string(name: "${PAYLOAD_PARAM}", value: BUILD_NUM))] } } } } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.