12

I upgraded Jenkins today from 1.618 to 2.3. This included installing a whole bunch of plugins that it recommended (Mostly Pipeline plugins and their dependencies).

Since the upgrade, I get a new error (or, at least, a new unwanted behavior) any time a job kicks off another job. Any values passed to the child as "Predefined parameters" are ignored unless the child job already has those keys defined.

Let me illustrate: Let's say that I have a parent job and a child job.

Parent launches child through a "Trigger parameterized build on other projects" Post-build Action. In the definition of that Post-build Action, under the "Predefined parameters", I have FOO=BAR defined.

In Jenkins 1.618, when child was triggered this way, it would have FOO set as a parameter, with a value of BAR.

But in 2.3, FOO is not set on that build of child.

If I modify child so that FOO is always a parameter of that job, it will then pick up the FOO=BAR set from parent. This is an unacceptable work-around because we pass dozens of parameters this way, and defining them on both ends is too fragile and violates the "don't repeat yourself" principle.

I get the same results whether I'm triggering the child job through through the "Trigger parameterized build on other projects" Post-build Action or through a MultiJob Phase of a MultiJob project.

Is this an intended change? Was it broken before, and we were just using it incorrectly? Or is this a bug?

PortMan
  • 4,205
  • 9
  • 35
  • 61

3 Answers3

28

According to Jenkins 2 Security updates, you can bypass it by setting:

hudson.model.ParametersAction.keepUndefinedParameters=true

To validate this workaround, go to Manage Jenkins -> Script Console, and run:

System.setProperty("hudson.model.ParametersAction.keepUndefinedParameters", "true")

To make it permanent, change Jenkins arguments as follow (and restart Jenkins afterwards):

On Windows edit jenkins.xml in Jenkins home directory, for example:

<arguments>
    -Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle
    -Dhudson.model.ParametersAction.keepUndefinedParameters=true 
    -jar "%BASE%\jenkins.war" --httpPort=8080
</arguments>

For most of the Linux distributions, you can modify JENKINS_ARGS inside file:

/etc/default/jenkins (or jenkins-oc)

For CentOS, modify JENKINS_JAVA_OPTIONS inside file:

/etc/sysconfig/jenkins (or jenkins-oc)

Here's a list of reported plugins, that were affected by the issue, and has an open bug already: https://wiki.jenkins-ci.org/display/JENKINS/Plugins+affected+by+fix+for+SECURITY-170

Noam Manos
  • 15,216
  • 3
  • 86
  • 85
  • How do you add `hudson.model.ParametersAction.keepUndefinedParameters=true` to the `linux` file **/etc/default/jenkins**? I tried add it with and without the `-D` at the start in the JENKINS_ARGS field. I can't seem to locate anyone notating how to do this either... – kayleeFrye_onDeck Oct 01 '16 at 06:23
  • 1
    For some reason, on my Debian install, adding the option to JENKINS_ARGS didn't work; instead it worked when adding it to JAVA_ARGS – Claudiu Dec 21 '16 at 16:15
  • 1
    Append `JAVA_ARGS="$JAVA_ARGS -Dhudson.model.ParametersAction.keepUndefinedParameters=true"` to **/etc/default/jenkins** (on Ubuntu) and restart Jenkins from the command line `sudo service jenkins restart`. – aoles Jan 25 '17 at 16:44
4

There are some solutions

  1. commabd line
    java -Dhudson.model.ParametersAction.keepUndefinedParameters=true -jar jenkins.war
  2. groovy
    import jenkins.model.*; System.setProperty("hudson.model.ParametersAction.keepUndefinedParameters", "true")
Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
Frank Yen
  • 93
  • 1
  • 1
  • 4
2

I couldn't find a Start-to-End answer on how to set this for a linux box. After a couple hours of cross-referencing guides, this is what ended up working. There are supposed to be a couple flavors of these Jenkins configurations. I'm using the Ubuntu flavor for this answer.

  1. Get the Groovy scripting plugin
  2. Discern where your $JENKINS_HOME is being set. By default, it's supposed to be at ~/.jenkins, but I didn't set this server up, so I had to go digging through some configuration files. In case you do too, this is what I had to do:
    • Check the contents of /etc/default/jenkins with vi to grab the value of $JENKINS_HOME -- mine was /var/lib/$NAME and further up the file, $NAME was set to jenkins, so it was /etc/libs/jenkins
  3. Change directories to the $JENKINS_HOME path
  4. Search for a directory called init.groovy.d -- if it doesn't exist, make one and then cd into it. You might have to use sudo if needing to make it
  5. Create a new file in the init.groovy.d directory that ends in .groovy -- I just called mine params.groovy
  6. Enter following script code into the groovy file we just made:
    • import jenkins.model.*; System.setProperty("hudson.model.ParametersAction.keepUndefinedParameters", "true")

Save and Close, then reboot your Jenkins server.

That should unblock you, if you ran into the same problem I did. Your mileage may vary :) I ultimately used a start-up script to utilize that functionality in conjunction with this solution proposed by Jenkins.

kayleeFrye_onDeck
  • 6,648
  • 5
  • 69
  • 80