Groovy Script

57 views
Skip to first unread message

eric....@gmail.com

unread,
Dec 9, 2022, 4:56:29 PM12/9/22
to Jenkins Users
Hi!  Not sure what's going on but I have a groovy script that has been setting the variable build_status for ages but it stopped working.   Doesn't set the variable any longer.  Any ideas?  Here's the script:

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

opay...@chsc.de

unread,
Dec 9, 2022, 11:50:34 PM12/9/22
to eric....@gmail.com, Jenkins Users
Hi,

you mean upstreamResult/build_result?

What does the println for upstreamResult say?
Which Jenkins version are you on?

BR :)

eric....@gmail.com

unread,
Dec 12, 2022, 10:46:27 AM12/12/22
to Jenkins Users
That's interesting.  The println looks like it should be correct:

upstream result: success

Later when I try to use the variable in an ant call, it just shows the variable instead of the value of it:

-Dbuild_result=${build_result}

I put it in the properties of the ant call:

full.buildnumber=${full.buildnumber}
build.time=${build.time}
pk_build=${pk_build}
build_result=${build_result}

This has always worked in the past, just not since this latest upgrade of jenkins.  I'm now on 2.375.1.

eric....@gmail.com

unread,
Dec 12, 2022, 2:27:56 PM12/12/22
to Jenkins Users
So I'm getting a different result on 2 different Jenkins servers.  I've upgraded on both.  The only difference between the 2 servers is that one is RHEL 7 and the other RHEL 8.  The RHEL 8 isn't working.  I have no clue why that is though.  It doesn't make sense that the same groovy script would behave differently in the 2 places.

eric....@gmail.com

unread,
Dec 12, 2022, 4:16:36 PM12/12/22
to Jenkins Users
Can someone please give me some println's I can put in there to figure out why it's not setting the build_result variable?  It doesn't make any sense to me that it works on one server but not another.  Thanks!

On Monday, December 12, 2022 at 8:46:27 AM UTC-7 eric....@gmail.com wrote:

opay...@chsc.de

unread,
Dec 13, 2022, 5:08:10 AM12/13/22
to eric....@gmail.com, Jenkins Users
How exactly do you pass the properties to ant?

eric....@gmail.com

unread,
Dec 13, 2022, 9:34:13 AM12/13/22
to Jenkins Users
I pass them in the properties of the Builder.  That said, I just figured out a way to make it work.  For some reason or another, I needed on this server to instantiate the property.  So I set it up top as build_result with a default value of fail.  Then when it hits the groovy script, it sets it correctly.  Since it sets it correctly, I'm guessing I didn't have to set a default value, just instantiate it.  Either way, it's working so I'm good.  Thanks for trying to help!
Reply all
Reply to author
Forward
0 new messages