TL DR: Obviously, in the Jenkins pipeline task, you can easily pass parameters downstream. I want to know if you can pass them upstream .
Use Case:
We have three tasks; job_one , job_two and job_three . They often start separately, since only one stage is required, but in more and more frequent cases we would like to be able to run all three back to back.
The first and second rely on parameters that you can determine in advance, but the third needs a parameter that is generated from the second job (the name of a file whose structure is unknown before job_two is run).
I built an umbrella that calls something like the following for each job. In this case, PARAM1 populated because the umbrella works like "Build with parameters".
build job: 'job_one', parameters: [[$class: 'StringParameterValue', name: 'PARAM1', value: "$PARAM1"]]
All thin and dandy, I can use PARAM1 in job_one just fine.
Problem:
For job_three I need the filename parameter. This is generated inside job_two , and therefore, from what I can say is not available, because job_three does not know what job_two does.
In an ideal world, I would just have job_two pass filename to the umbrella job, which will return it to job_three. Thus , how can I transfer the generated filename backup to the umbrella job?
I present the final script with something like this:
node('on-demand-t2small'){ stage ('Build 1') { build job: 'job_one', parameters: [[$class: 'StringParameterValue', name: 'PARAM1', value: "$PARMA1"]] } stage ('Build 2') { build job: 'job_two', parameters: [[$class: 'StringParameterValue', name: 'PARAM2', value: "$PARMA2"]] //somehow get the filename parameter out of job_two here so that I can move it to job three... } stage ('Build 3') { build job: 'job_three', parameters: [[$class: 'StringParameterValue', name: 'filename', value: "$filename"]] } }
Additional notes:
I understand that the first question will be "why not run job_two job_three?" I cannot install the system this way for two reasons:
- job_two should be able to run job_three without starting, and three may not always run two inputs.
- I discussed the issue that the umbrella started with two, and then has a point in two that will launch three ONLY IF it was launched by the umbrella, but, as far as I can tell, this will limit the feedback in the operation of the umbrella; you donβt know if two were unsuccessful because two refused, or because three (as part of two) failed. If I am mistaken about this assumption, please let me know.
I thought about setting the parameter as an environment variable, but I believe that the node is specific, and I can not guarantee that both tasks will be performed on the same node so that this is not a solution.
Umbrella is a pipeline job written in groovy, the other three can be pipelined or freestyle jobs, if that matters.
I would appreciate the detailed answers, if possible, I'm still new to groovy, Jenkins and general coding.