Skip to main content

How to set build name in Pipeline job?

Comments

6 comments

  • Anna Kordas

    Actually it changes the build description not build name, so the post title can be confusing. Resolution is currentBuild.displayName

    2
  • Permanently deleted user

    We will update the article with the changes.

    0
  • Hernán Schmidt

    What is the equivalent for this in a declarative pipeline?

    0
  • Allan Burdajewicz

    Hernán

    In declarative you must use the script { ... } block.

    pipeline {
        stages {
            stage("Build"){
                steps {
                    script {
                        currentBuild.displayName = "The name."
                        currentBuild.description = "The best description."
                    }
                    ... do whatever.
                }
            }
        }
    }

     

    0
  • Badal Kotecha

    @Hernan & @Allan that does not work in declarative pipeline.

    I also tried

     

    pipeline {
        stages {
            stage("Build"){
                steps {
                    script {
                        env.currentBuild.displayName = "The name."
                        env.currentBuild.description = "The best description."
                    }
                    ... do whatever.
                }
            }
        }
    }

    But 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)
     
    0
  • Allan Burdajewicz

    @Badal My script is missing the `agent` directive, the following should work as is:

    pipeline {
    agent any stages { stage("Build"){ steps { script { currentBuild.displayName = "The name." currentBuild.description = "The best description." } } } } }

    If it does not, please file a support request so that we can troubleshoot this further.

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

     

    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.