Groovy Script Not Working

87 views
Skip to first unread message

Eric Fetzer

unread,
Nov 18, 2016, 10:03:25 AM11/18/16
to Jenkins Users
I've recently upgraded Jenkins from an older version to modern version (2.19.2).  In the old version, my Groovy code worked well to gather the upstream build results.  It has stopped working.  I'm wondering if something has changed.  Here is my code:

import hudson.model.*
import jenkins.model.*
 
def resolver = Thread.currentThread().executable.buildVariableResolver
def parent_job = resolver.resolve("upstream_job")
def parent_build_number = resolver.resolve("upstream_bn")
def upstreamResult = Hudson.instance.getJob("${parent_job}").getLastBuild().result
if(upstreamResult.equals(hudson.model.Result.FAILURE)) {
  upstreamResult
= "fail"
} else {
  upstreamResult
= "${upstreamResult}".toLowerCase()  
}
println
"upstream result: ${upstreamResult}"
def newParams = null
def pl = new ArrayList<StringParameterValue>()
pl
.add(new StringParameterValue('build_result', upstreamResult))
def oldParams = build.getAction(ParametersAction.class)
if(oldParams != null) {
  newParams
= oldParams.createUpdated(pl)
  build
.actions.remove(oldParams)
} else {
  newParams
= new ParametersAction(pl)
}
build
.addAction(newParams)


Thanks,
Eric

Daniel Beck

unread,
Nov 18, 2016, 10:45:20 AM11/18/16
to jenkins...@googlegroups.com

> On 18.11.2016, at 16:03, Eric Fetzer <eric....@gmail.com> wrote:
>
> It has stopped working.

What happens instead?

Eric Fetzer

unread,
Nov 18, 2016, 11:33:49 AM11/18/16
to Jenkins Users
The result of running this should set the variable ${build_result}, but that is not set on the other side.  Here's the output from the build when it goes into the groovy script:

Building in workspace /var/lib/jenkins/workspace/Audit
Run condition [Numerical comparison] enabling prebuild for step [Invoke Ant]
upstream result: success

So it looks to me like it should be setting build_result to success but it doesn't.  Any hints on debugging?

THanks!

Eric Fetzer

unread,
Nov 18, 2016, 3:53:49 PM11/18/16
to Jenkins Users
Well, I found out a little more by putting a few println's in there.  When it hits the: if(oldParms != null), it goes in to set newParams from oldParams.  I'm not sure what that really buys me though...



On Friday, November 18, 2016 at 8:03:25 AM UTC-7, Eric Fetzer wrote:

Eric Fetzer

unread,
Nov 18, 2016, 4:08:49 PM11/18/16
to Jenkins Users



On Friday, November 18, 2016 at 8:03:25 AM UTC-7, Eric Fetzer wrote:

Eric Fetzer

unread,
Nov 18, 2016, 4:39:44 PM11/18/16
to Jenkins Users
OUCH!  That was it!  Added the following parameter to my /etc/sysconfig/jenkins file, restarted jenkins, and it worked:

-Dhudson.model.ParametersAction.keepUndefinedParameters=true



On Friday, November 18, 2016 at 8:03:25 AM UTC-7, Eric Fetzer wrote:
Reply all
Reply to author
Forward
0 new messages