How to set the pipeline name and description for a Jenkinsfile?

+4 votes
I have a Jenkins pipeline as code and I'm trying to do a POC for the same. I have the Github organization folder plugin. I had a small doubt, Is it possible to explicitly define the name for the pipeline jobs in jenkinsfile? Can I also add some description to those jobs?
Mar 25, 2018 in Jenkins by Atul
• 10,240 points

recategorized Aug 6, 2018 by Vardhan 8,472 views

7 answers to this question.

+2 votes

Hey I finally figured, if anyone needs help. 

As mentioned by @Krishti, you need to use the current Build as follows.(The node part is important)

node {
    currentBuild.displayName = "$yournamevariable-$another"
    currentBuild.description = $yourdescriptionvariable-$another"
     }
answered Mar 25, 2018 by Atul
• 5,530 points

edited Oct 11, 2018 by Kalgi
Thanks a lot, saved a lot of my time:)
+2 votes
To set the JOB description and JOB display name for a child in a multi-branch declarative pipeline use the following steps block in a stage:
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 the individual script calls through the Jenkins sandbox approval method

answered Aug 3, 2018 by Nilesh
• 6,880 points
+2 votes

You can rename pipeline jobs in jenkins using the following script, edit is as per your requirement.

item = Jenkins.instance.getItemByFullName("original Job Name")
item.setDescription("Changes Description")
item.save()
item.renameTo("New Job Name")
answered Oct 11, 2018 by Hannah
• 16,730 points
+1 vote

Try this:

node {
    currentBuild.displayName = "fooName"
    currentBuild.description = "fooDescription"
}
answered Dec 10, 2018 by krishti
+1 vote

This worked for me:

def setDescription() { 
    def item = Jenkins.instance.getItemByFullName(env.JOB) 
    item.setDescription("Description") 
    item.save()
}

setDescription()
answered Dec 10, 2018 by Kanika
+1 vote

Try this, using currentBuild

pipeline {
    stages {
        stage("Build"){
            steps {
                script {
                    env.currentBuild.displayName = "The name."
                    env.currentBuild.description = "The best description."
                }
                ... 
        }
    }
}
answered Dec 10, 2018 by Neha

This didnt work for me, it throws NullPointerException error as shown below

java.lang.NullPointerException: Cannot set property 'displayname' on null object
	at org.codehaus.groovy.runtime.NullObject.setProperty(NullObject.java:80)
	at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:197)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:484)
	at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:347)

currentBuild is a Groovy variable, not an environment variable. So you cannot use env.

+1 vote

Hey @Atul, You can use the build name setter plugin. This plugin sets the display name of the build. By default the builds are given weird names like #1, #2.. You are allowed to explicitly change these names and add description according to your likings using this plugin. 

answered Apr 8 by Andis

Related Questions In Jenkins

0 votes
1 answer
0 votes
2 answers

How to trigger a Jenkins pipeline A in another Jenkins pipeline B?

If you are talking about executing another ...READ MORE

answered Jul 31 in Jenkins by Sirajul
• 39,540 points
6,674 views
+1 vote
3 answers
0 votes
3 answers

How to get the Maven Version of a project in Jenkins?

Here is a snippet from our Jenkins ...READ MORE

answered Oct 4 in Jenkins by Petr Doležal
1,749 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
217 views
0 votes
1 answer