Job parameters in Jenkins 2.X

119 views
Skip to first unread message

Nick Grealy

unread,
Aug 3, 2016, 12:35:51 PM8/3/16
to Jenkins Developers
Hi all,

This should be a simple question to answer...

Before Jenkins 2.X, I used to be able to execute a Job programatically with the following code:


import jenkins.model.*;
import hudson.model.*;

// kick off a job...  
FreeStyleProject job = Jenkins.getInstance().getJob('QuickTest');
job
.scheduleBuild2(0, new Cause.UserIdCause(),
 
new ParametersAction(Arrays.asList(
   
new StringParameterValue('aaa', 'zzz'), // exists in job's defined parameters
   
new StringParameterValue('bbb', 'yyy')  // doesn't exist in job's defined parameters
)));



This would execute a new instance of a job, with two parameters - aaa=zzz and bbb=yyy. Perfect.

Now, post Jenkins 2.X, I get the same behaviour, EXCEPT the bbb parameter does not get injected (i.e. only defined parameters are included in the job).

  • How do I get bbb injected as (preferably) a build parameter (or failing that, an environment variable)?
Kind regards,

Nick


Slide

unread,
Aug 3, 2016, 12:40:49 PM8/3/16
to Jenkins Developers
You need to add "bbb" as a parameter to the job. Jenkins will now only pass thru parameters that are defined in the job that you are passing them to.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/bd1e7ee7-666e-48a3-a68e-ecb972511b39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nick Grealy

unread,
Aug 3, 2016, 2:54:20 PM8/3/16
to Jenkins Developers
Ok, what happens when the parameter names are dynamic (ie. Not known in advance)?

Should I be using environment variables instead? (How do I add them programmatically?)

Thanks

Baptiste Mathus

unread,
Aug 3, 2016, 3:30:24 PM8/3/16
to Jenkins Developers

It won't work as of SECURITY-170.

See https://wiki.jenkins-ci.org/display/SECURITY/Jenkins+Security+Advisory+2016-05-11 for details.

Can't you list all of those parameters with some left undefined depending on the build?

Cheers


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.

Nick Grealy

unread,
Aug 3, 2016, 7:56:17 PM8/3/16
to Jenkins Developers, m...@batmat.net
Thanks Baptiste, that's good to know (or not :( ).

A bit of background, this is in regard to maintaining the poll-mailbox-trigger-plugin - I'll add it to the following list of "Plugins affected by fix for SECURITY-170".

As the plugin maintainer, can I inject variables programmatically, as environment variables instead?

OR should I advise users to do one of the following:
  • explicitly add parameters to their jobs?
  • define a -Dhudson.model.ParametersAction.safeParameters=FOO,BAR property?
  • define a -Dhudson.model.ParametersAction.keepUndefinedParameters=true property?
Kind regards,

Nick

Daniel Beck

unread,
Aug 3, 2016, 8:00:31 PM8/3/16
to jenkin...@googlegroups.com

> On 04.08.2016, at 01:56, Nick Grealy <nickg...@gmail.com> wrote:
>
> As the plugin maintainer, can I inject variables programmatically, as environment variables instead?
>

EnvironmentContributor is the extension point for that.

To pass parameters to the build, you could define a QueueAction that holds the relevant values, and then have an EnvironmentContributor make them into env vars.

Nick Grealy

unread,
Aug 3, 2016, 8:11:37 PM8/3/16
to Jenkins Developers, m...@beckweb.net
Thanks Daniel, I'll give that a go.

Nick Grealy

unread,
Aug 5, 2016, 6:59:08 AM8/5/16
to Jenkins Developers, m...@beckweb.net

Oleg Nenashev

unread,
Aug 6, 2016, 3:33:27 AM8/6/16
to Jenkins Developers, m...@beckweb.net
Thanks for the fix!
I've updated https://wiki.jenkins-ci.org/display/JENKINS/Plugins+affected+by+fix+for+SECURITY-170

пятница, 5 августа 2016 г., 13:59:08 UTC+3 пользователь Nick Grealy написал:
Reply all
Reply to author
Forward
0 new messages