My multibranch project in Jenkins works fine, but I would like to modify the job description, which is by default "Full project name: xxxx/", to something more meaningful.
I can easily change the build description by using the currentBuild
variable that is available when my Jenkinfile
is executed, but I can't figure how to modify the parent job description.
My use case is that each branch of my repository has an associated container that is updated with the latest build when it is finished. So each of the jobs in my multibranch project has its container and web URI, that I would like to put into the job description.
Is this possible?
How about using the Jenkins Api to update the current job's description? Something like:
To update the top multibranch project description:
def jobName = "${env.JOB_NAME}"
Jenkins.instance.getItem(jobName.split('/')[0]).description = "hi"
To update a specific branch project's description in the multibranch project:
def jobName = "${env.JOB_NAME}"
Jenkins.instance.getItem(jobName.split('/')[0]).getItem("${env.BRANCH_NAME}").description = "hi"
Note: You will need to approve several functions via "Manage Jenkins" -> "In process Script Approval"
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance
:-(I think you should be able to approve it by going to "Manage Jenkins" -> "In-process Script Approval". Let me know if otherwise.
Wow, this changes everything. I figured you couldn't access global variables from the Jenkinsfile, but this "In Process script approval" is awesome. Thank you Daniel.
Thank you Daniel. I had to escape the branch name in my case, because it contains "/" (slashes) that are converted to "%2F", but overall it works.