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 36,242 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 ffdfd
• 5,550 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
• 7,060 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
• 18,540 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, 2019 by Andis

Related Questions In Jenkins

0 votes
1 answer

How to change the image that the slave uses for a jenkins pipeline?

Hi@akhtar, You can specify the Docker images directly ...READ MORE

answered Oct 22, 2020 in Jenkins by MD
• 95,460 points
1,065 views
0 votes
1 answer

how to create a job using jenkins for Sign the puppet certificate on master ?

Take a look at this  https://fullstack-puppet-docs.readthedoc ...READ MORE

answered May 29, 2020 in Jenkins by Sirajul
• 59,230 points
1,102 views
0 votes
1 answer

How to set permissions for a user in Jenkins?

Hi@akhtar, You can give access to your user ...READ MORE

answered Dec 7, 2020 in Jenkins by MD
• 95,460 points
36,374 views
0 votes
1 answer
+5 votes
3 answers

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
• 10,620 points
119,531 views
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,987 views
+2 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP