Categories
DevOps

How to define build name and description in Jenkins

Define build name and description in Jenkins pipeline.

Use currentBuild.displayName and currentBuild.description to define build name and description.

pipeline {
    agent any    
    options {
        disableConcurrentBuilds()
    }
    parameters {
        choice(
            name: 'deployDestination',
            choices: "Devel\nTesting\nProduction",
            description: 'Choose deploy destination' )
    }    
    
    stages {
        stage("Set description") {
            steps {
                script {
                    currentBuild.displayName = "Deploy on ${params.deployDestination} [#${BUILD_NUMBER}]"
                    currentBuild.description = "Destination: ${params.deployDestination}\n" +
                                               "Executed on: ${NODE_NAME}\n"
                }
            }
        }
        stage("Wait") {
            steps {
                sleep time: 25, unit: 'SECONDS' 
            }
        }
    }
    
    post {
        always {
            cleanWs()
        }
    }
}

This is a handy feature as you can use it to display git branch, commit hash, author, or just specified parameters.