Jenkins multibranch: change Job Description from Groovy

My multi-brand project in Jenkins works fine, but I would like to change the job description, which by default is "Project Full Name: xxxx /", for something more meaningful.

I can easily change the assembly description using the currentBuild variable, which is available when my Jenkinfile is running, but I cannot figure out how to change the parent description of the job.

My use case is that each branch of my repository has an associated container that updates with the latest build when it is complete. Thus, each of the tasks of my multi-brand project has its own container and web URI, which I would like to include in the job description.

Is it possible?

0
git jenkins groovy
source share
2 answers

How about using Jenkins Api to update the current job description? Something like:

To update the description of the top multi-brand project:

 def jobName = "${env.JOB_NAME}" Jenkins.instance.getItem(jobName.split('/')[0]).description = "hi" 

To update the description of a specific industry project in a project with several channels:

 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 through "Managing Jenkins" -> "In-Process Script Approval"

+2
source share

I wrote this function. It supports working in a folder. Remember to allow the use of the sandbox: Managing Jenkins "->" In-process Script Statement "

 @NonCPS def setJobDescription(text){ def jobNameTable = env.JOB_NAME.split('/') def it=Jenkins.instance for(name in jobNameTable){ it=it.getItem(name) } it.description = text } 
+1
source share

All Articles