Jenkins - passing variables between jobs?

前端 未结 10 1625
你的背包
你的背包 2020-11-28 06:53

I have two jobs in jenkins, both of which need the same parameter.

How can I run the first job with a parameter so that when it triggers the second job, the same pa

相关标签:
10条回答
  • 2020-11-28 07:30

    You can use Hudson Groovy builder to do this.

    First Job in pipeline

    enter image description here

    Second job in pipeline

    enter image description here

    0 讨论(0)
  • 2020-11-28 07:33

    I figured it out!

    With almost 2 hours worth of trial and error, i figured it out.

    This WORKS and is what you do to pass variables to remote job:

        def handle = triggerRemoteJob(remoteJenkinsName: 'remoteJenkins', job: 'RemoteJob' paramters: "param1=${env.PARAM1}\nparam2=${env.param2}")
    

    Use \n to separate two parameters, no spaces..

    As opposed to parameters: '''someparams'''

    we use paramters: "someparams"

    the " ... " is what gets us the values of the desired variables. (These are double quotes, not two single quotes)

    the ''' ... ''' or ' ... ' will not get us those values. (Three single quotes or just single quotes)

    All parameters here are defined in environment{} block at the start of the pipeline and are modified in stages>steps>scripts wherever necessary.

    I also tested and found that when you use " ... " you cannot use something like ''' ... "..." ''' or "... '..'..." or any combination of it...

    The catch here is that when you are using "..." in parameters section, you cannot pass a string parameter; for example This WILL NOT WORK:

        def handle = triggerRemoteJob(remoteJenkinsName: 'remoteJenkins', job: 'RemoteJob' paramters: "param1=${env.PARAM1}\nparam2='param2'")
    

    if you want to pass something like the one above, you will need to set an environment variable param2='param2' and then use ${env.param2} in the parameters section of remote trigger plugin step

    0 讨论(0)
  • 2020-11-28 07:36

    You can use Parameterized Trigger Plugin which will let you pass parameters from one task to another.

    You need also add this parameter you passed from upstream in downstream.

    0 讨论(0)
  • 2020-11-28 07:38

    1.Post-Build Actions > Select ”Trigger parameterized build on other projects”

    2.Enter the environment variable with value.Value can also be Jenkins Build Parameters.

    Detailed steps can be seen here :-

    https://itisatechiesworld.wordpress.com/jenkins-related-articles/jenkins-configuration/jenkins-passing-a-parameter-from-one-job-to-another/

    Hope it's helpful :)

    0 讨论(0)
提交回复
热议问题