[workflow-plugin] Passing parameters to triggered jobs

473 views
Skip to first unread message

excessgr

unread,
Nov 24, 2014, 3:10:08 AM11/24/14
to jenkins...@googlegroups.com
I'm a bit confused as to how to pass parameters to triggered jobs.
The snippet generator says I can pass a list of ParameterValues, but I'm really unfamiliar with the internals of jenkins so I'm not sure how I can pass this list.

I assume this is what the list should look like:
ArrayList<ParameterValue> parameters=new ArrayList<ParameterValue>();
parameters
.add(new hudson.model.StringParameterValue('PARAM','123'));


However I'm checking the constructor of the build step and there is no such parameter to pass through.
How do I use the setter before the build is executed?

Thanks.

James Nord

unread,
Nov 24, 2014, 6:19:15 AM11/24/14
to jenkins...@googlegroups.com
Hi,

the syntax is something like

ArrayList<ParameterValue> yourparamaters=new ArrayList<ParameterValue>();
yourparamaters.add(new hudson.model.StringParameterValue('PARAM','123'));

build  job: 'yourJobNameToBuild', parameters: yourparamaters

you can also shorthand this if you don;t need to re-use the same parameters

build  job: 'yourJobNameToBuild', parameters: [new hudson.model.StringParameterValue('PARAM1','123'), new hudson.model.StringParameterValue('PARAM2','345')]

However - I would caution against using the workflow to trigger other jobs if you can - It's ideal is to self contain the workflow and steps in a single place so you don't have configuration sprawl (the workflow and all the configuration of it is defined in one single place).

/James

excessgr

unread,
Nov 24, 2014, 7:26:44 AM11/24/14
to jenkins...@googlegroups.com
Thank you James!
Eventually yes we'd like to merge them all into one job, but since for now the plugin is missing support for some build steps that we're using, I guess this is the only way to get it done.

Jesse Glick

unread,
Jan 8, 2015, 3:47:17 PM1/8/15
to jenkins...@googlegroups.com
On Monday, November 24, 2014 at 6:19:15 AM UTC-5, James Nord wrote:
build  job: 'yourJobNameToBuild', parameters: [new hudson.model.StringParameterValue('PARAM1','123'), new hudson.model.StringParameterValue('PARAM2','345')]

Though this should be replaced with a more idiomatic form requiring no direct access to Jenkins APIs: https://issues.jenkins-ci.org/browse/JENKINS-26093
Reply all
Reply to author
Forward
0 new messages