Jenkins - How can i pass parameters from the Upstream to Downstream
Asked Answered
D

6

6

I have 3 builds: A - is the Master build which control the flow B- Anoter build C- will be executed after B I want to add a String parameter to A so the user will enter some String manually, and i'm not sure how can i path this parameter to B. lets say that this is my build flow:

build("B") build("C") I don't know how can i path the parameter to B, should i do that from the build flow or from the B build configuration and how can i do that.

Thanks in advance Alex

Deity answered 14/8, 2014 at 14:52 Comment(1)
I just noticed that you have asked the same question before. Why are you creating duplicates?Hemorrhoidectomy
G
3

Something like this:

build("B", B_parameter: params["A_parameter"])<br>
build("C")

https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin

Gesualdo answered 13/11, 2014 at 20:58 Comment(1)
Build Flow Plugin seems obsolete, people recommend to use the Pipeline plugin nowadays: #35284603Celibate
L
2

One way to do this is with the Parameterized Trigger plugin: https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin

This allows you to trigger another job using, but not limited to:

* a set of predefined properties 
* properties from a properties file read from the workspace of the triggering build
* the parameters of the current build

With Build A, B, and C you set th3m up as a parameterized builds (i.e. to ask for a value for a parameter). This a setting near the start of the job config page. For example to take a parameter you name MY_ID. This is now accessible as $MY_ID in build A.

Now, when you build A an it prompts for MY_ID. Then add a build step in Job A to trigger "B" with parameters, and pass it all the parameters of build A. Now build B will also have the parameter $MY_ID that was set when you ran a build of A.

Levitation answered 14/8, 2014 at 14:59 Comment(8)
Should i write it in the Define build flow using flow DSL ? If yes can you show me, now all i have there is : build("B") build("C") and i just want to make sure i need to set up all the builds as parameterized and not only the root build which is 'A' in my case.Deity
Sorry, I don't use DSL--I configure all my flows manually through the UILevitation
so how can i configure the flow using the UI? i didn't find an option .. can you send me a snapshot?Deity
To enable parameters on a project, in the configuration screen about the 4th option down is 'This build is parameterized'. My screen shows: Project Name, Descripts, Discard Old builds, then a check box 'This build is parameterized'. Check it, then you can add parameters.Levitation
lets say it was done on the upstream how can i pass this parameter to the childstream (downstream), because i know how to add parameters to jecnkinsDeity
Ok, install teh parameterized Trigger plugin. After that in your section 'Build' section and 'Post Build Actions' you can add a 'Trigger/call builds on other project' and add parameters or set of parameters to pass to the downstream project.Levitation
i've done this when i'm running the scripts on the downstream using the name of upstream parameters $VERSION_NUMBER for example it doesn't get the value in the script... any idea?Deity
@user3502786 you have to set the downstream project to be parameterized as well, and specify a parameter named exactly after any defined in the parent that you want to use. Is Project B configured build with parameters, one of which is named 'VERSION_NUMBER'?Levitation
H
2

Parameterized Trigger Plugin is what you're looking for. For details on how to pass parameter from master build to child build, check my answer in this link.

Hemorrhoidectomy answered 14/8, 2014 at 15:31 Comment(0)
O
1

Wooooow, so after a couple hours of playing "Which plugin is missing from this equation?", it turned out that none of these answers worked due to a jenkins change called SECURITY-170.

If you followed the steps in this answer and your parameters are not being forwarded, please go to this other Stack Overflow answer which provides the details of the issue. If you're feeling too lazy and just want to verify that SECURITY-170 is the crux of the issue, you can try this temporary solution, as it does not persist after reboot:

  1. Manage Jenkins -> Manage Nodes -> Select your "Master", whatever it's named
  2. Select the Script Console
  3. Paste this in and hit the Run button: System.setProperty("hudson.model.ParametersAction.keepUndefinedParameters", "true")
  4. Retry the build that wasn't forwarding parameters

If that worked for you, you can check this answer I assembled on another question, but I would advise you read both the question and the context of my answer before attempting it.

Overpower answered 1/10, 2016 at 4:41 Comment(0)
K
0

Here is my pipeline (Master Build A) scripts to pass parameters to child jobs (Child Build B)

build job: 'svn test', parameters: [string(name: 'srcpath', value: params["mainpath"]), string(name: 'revision', value: params["mainrevision"])]

I configure
-- mainpath and mainrevision as pipeline jobs parameters,
-- srcpath and revision as child jobs parameters

Kummerbund answered 23/5, 2017 at 4:9 Comment(0)
T
0

try this method

def myparams = currentBuild.rawBuild.getAction(ParametersAction).getParameters()
build job: 'Downstream JOb', parameters: myparams, wait: true
Their answered 29/3 at 13:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.