how to update build name (aka displayName) via API

1,463 views
Skip to first unread message

Karl Ostmo

unread,
Dec 12, 2015, 3:42:43 AM12/12/15
to Jenkins Users
I would like to set the name of a build programmatically during an "Execute shell" step.  The new name of the build must be calculated based on some code that runs in the shell.

To clarify, the build name is the value that shows up in the "Build Executor Status" left sidebar on the main Jenkins page and also the "Build History" left sidebar from any Job page.  Normally this value is the build number prefixed with a pound sign.

I have looked at the Build Name Setter Plugin (https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin), but I do not believe I can use it to set the build name as early in the build process as I would like.  Therefore I am investigating the REST API.


First, I was able to retrieve the build name (referred to as the "displayName") via the REST API using curl:

curl -s --user <username>:<password> --data-urlencode "tree=displayName" http://jenkins.teslamotors.com/job/firmware-repo/5111/api/json




As an experiment, I was able to set the build "description", using the curl command described here:
but I was not able to set the build "name".


I came across this Python code that purports to update the build name ("displayName"), but I could not get it to work myself:


Does there exist a method (that works today) for one to set a new build name via curl?

Victor Martinez

unread,
Dec 12, 2015, 9:28:24 AM12/12/15
to Jenkins Users
My two cents,

1) Split your build step in two parts and use the envinject plugin.

Your first step will generate the build name and save to a file.
Then, you can inject that via the envibject plugin and use the set build name based on that property. Afterwards you can run your script.

2) if you don't mind running that action as part of the post build you could use the groovy y post build plugin.

3) if you use some system groovy script step you could rename your build name on the fly rather than as part of the post build action (have a look at the groovy plugin).

I hope it helps, maybe someone else already got another easy workaround

Cheers


Reply all
Reply to author
Forward
0 new messages