How can I set the build description from a parameter?

1,394 views
Skip to first unread message

cscooper

unread,
Dec 3, 2013, 7:08:50 PM12/3/13
to jenkins...@googlegroups.com
I've got a parameterized matrix build, one of the parameters is called
"Description" and in the "Prepare an environment for the run" section, under
"Script Content", I have this:
curl -G -s --data-urlencode "Description=$Description"
"http://localhost:8080/job/$JOB_NAME/$BUILD_NUMBER/submitDescription"
this works great to set the description of the build according to the
Description parameter, and do so early on in the build (I'm not as happy
with the plugins that set the description at the end of the build).

HOWEVER

when the Matrix part of the job kicks in, this code gets executed again on
my Linux box which chokes because it's only a slave so http://localhost:8080
doesn't mean anything.

I thought about actually specifying the IP, so the "submitDescription" would
go to the actual build server, but in the matrix build $JOB_NAME is now
"Job/Matrix=linux" so the URL isn't right anyway.

AND

I've also got a Windows slave, and "curl" just completely confuses him.

I tried writing an "if" statement in the "Script Content" - something like
this:

if [[ "$NODE_NAME" = "master" ]]; then
curl -G blah blah blah
fi

but (1) Jenkins wasn't at all happy with that, and (2) even if Jenkins
accepted it, my Windows slave would choke on it.

* Is there a better way to set the build description from a parameter?
* Is there a way to have Jenkins prepare the environment differently on
different nodes?
* Is there a trick to putting a value in "Script File Path" such that it
runs correctly on both Windows and Linux slaves?
* Is there something clever I can do with a Groovy script here?

Thanks for any and all advice!
Chris





--
View this message in context: http://jenkins-ci.361315.n4.nabble.com/How-can-I-set-the-build-description-from-a-parameter-tp4683192.html
Sent from the Jenkins users mailing list archive at Nabble.com.

Matthew...@diamond.ac.uk

unread,
Dec 4, 2013, 3:45:24 AM12/4/13
to jenkins...@googlegroups.com
Here is the Groovy script I use, which gets the description from the log. You can modify as required to use an environment variable (I think).
Matthew Webber

// This Groovy script must be run using a Jenkins "Execute system Groovy script" build step
// A previous step must write a line in the log of the form defined in "pattern" below

def currentBuild = Thread.currentThread().executable
def pattern = /^set-build-description: (.+)$/

// Parsing 20 most recent lines of the build log
log = currentBuild.getLog(20)
for (line in log) {
match = (line =~ pattern)
if (match) {
currentBuild.setDescription(match[0][1])
out.println "[set-build-description.groovy] Build description was set to: " + match[0][1]
break
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom




Chris Cooper

unread,
Dec 4, 2013, 12:04:06 PM12/4/13
to jenkins...@googlegroups.com
Excellent, thank you!

For future reference, my final solution is really simple:

1) In each job I have a string parameter named "Reason" with a default
value of "Manual build". FYI, for each such job I have a matching
"Nightly" job that is triggered every midnight-ish, all it does is trigger
the main job with the Reason parameter set to "Nightly build", and I also
have a system to accept CVS commit triggers and the details of those
commits also get sent to the main job with the Reason parameter set to
"CVS Change" and the details.

2) "Prepare an environment for the run" is checked (enabled).

3) "Evaluated Groovy script" contains one line:
currentBuild.setDescription(currentBuild.buildVariableResolver.resolve("Rea
son"))

Voila!

BTW, most of my jobs are matrix jobs, and so the slaves also end up
executing this Groovy script, so I end up setting the description 4 times
(1 master, 3 slaves) which annoys my sensibilities but is otherwise not a
problem.

Chris

On 12/4/13 1:45 AM, "Matthew...@Diamond.ac.uk"
>--
>You received this message because you are subscribed to the Google Groups
>"Jenkins Users" group.
>To unsubscribe from this group and stop receiving emails from it, send an
>email to jenkinsci-use...@googlegroups.com.
>For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages