Search code examples
jenkinsgroovyjenkins-pluginsjenkins-workflowjenkins-pipeline

Pass some values from one job to another


I have three jobs which will be built inside a pipeline job as below

build 'job1'
build 'job2'
build 'job3'

job2 can take 2 parameters. Which should be coming from job1. Let job1 is creating a folder in some particular location (eg; C:\tests). I need to pass the name of the folder which is created job1 to job2. How can I do that ?

I need the same parameters to be passed to job3 also.

What can I do in job1 and in the pipeline to send and receive these parameters ?

I don't want to edit the job1 to have post build options to build job2 with parameters.


Solution

  • From job1:

    env.SOMETHING = someValue
    

    Define the parameters in job2. In the master job,

    def b1 = build 'job1'
    def something = b1.buildVariables.SOMETHING
    build job: 'job2', parameters: …