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,190 points

recategorized Aug 6, 2018 by Vardhan 3,950 views

7 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+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,470 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,900 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
• 14,080 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
1 answer

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

You can run the following code, its ...READ MORE

answered Jul 5, 2018 in Jenkins by Sophie may
• 9,050 points
708 views
+1 vote
3 answers
0 votes
1 answer

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

Follow the below steps: 1.      Install the Groovy ...READ MORE

answered Aug 9, 2018 in Jenkins by Sophie may
• 9,050 points
124 views
+5 votes
4 answers

How can I run a Jenkinsfile from a particular folder?

Consider the below points: The Freestyle project ...READ MORE

answered Mar 26, 2018 in Jenkins by anonymous
746 views
+13 votes
2 answers
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.