Warm tip: This article is reproduced from stackoverflow.com, please click
git groovy jenkins

Jenkins multibranch: change Job description from Groovy

发布于 2020-04-18 10:00:30

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?

Questioner
Gui13
Viewed
59
Daniel Omoto 2016-08-30 06:14

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"