Set the name and description of the pipeline from the Jenkinsfile

I am trying to make poc jenkins pipe as code. I use the Github organization folder plugin to scan Github organizations and create tasks for each branch. Is there a way to explicitly define names for pipeline jobs that come from Jenkinsfile? I also want to add some job descriptions.

+7
devops jenkins jenkinsfile
source share
3 answers

You need to use currentBuild as shown below. The important part of node

 node { currentBuild.displayName = "$yournamevariable-$another" currentBuild.description = "$yourdescriptionvariable-$another" } 

Edit: over one renaming assembly, where is the original question of renaming tasks. After the script in the pipeline, it will do (this requires appropriate permissions )

 item = Jenkins.instance.getItemByFullName("originalJobName") item.setDescription("This description was changed by script") item.save() item.renameTo("newJobName") 
+11
source share

I tried using the code snippet from the accepted answer to describe my Jenkins pipeline in the Jenkinsfile. I had to wrap a piece of code in a function using the @NonCPS annotation and use def for the item variable. I placed the code snippet in the root directory of Jenkinsfile, and not in the node section.

 @NonCPS def setDescription() { def item = Jenkins.instance.getItemByFullName(env.JOB_NAME) item.setDescription("Some description.") item.save() } setDescription() 
+2
source share

I'm late to the party on this one, but this question got me into #jenkins chat where I spent most of my day today. I would like to thank @tang ^ from this chat for helping to solve this gracefully for my situation.

To set the JOB description and JOB display name for the child in the DECLARATIVE pipeline, use the following step in the step:

 steps { script { if(currentBuild.rawBuild.project.displayName != 'jobName') { currentBuild.rawBuild.project.description = 'NEW JOB DESCRIPTION' currentBuild.rawBuild.project.setDisplayName('NEW JOB DISPLAY NAME') } else { echo 'Name change not required' } } } 

This will require that you approve individual script calls through the Sandbox Sanden approval method, but it was much simpler than anything I found on the Internet about renaming the actual children of the parent pipeline. The last thing to note is that this should work in a Jenkins file, where you can use environment variables to manage installed tasks.

0
source share

All Articles