Operations 4 min read

How to Update Jenkins Build Name and Description Using currentBuild Variables

This article explains how to customize Jenkins build names and descriptions by setting the currentBuild.displayName and currentBuild.description variables within a pipeline, providing a sample script that incorporates environment, server group, and artifact version details for clearer build identification.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
How to Update Jenkins Build Name and Description Using currentBuild Variables

Jenkins is a widely used CI tool that can also handle build and release automation. By default it sets the build name to the build number, which makes it hard to know which environment and server group a particular build was deployed to.

To make build information visible directly in the build list, you can update the currentBuild.displayName and currentBuild.description variables in your pipeline script. This allows the build number, target environment, server group, and artifact version to be shown without opening the job details.

pipeline {
    agent any

    parameters {
        choice choices: ['develop', 'test', 'stage', 'prod'], description: 'Select the target environment.', name: 'ENVIRONMENT_NAME'
        choice choices: ['ServerGroupA', 'ServerGroupB', 'ServerGroupC'], description: 'Select the target server group name.', name: 'SERVER_GROUP_NAME'
        string defaultValue: '1.0.0', description: 'Enter artifact version to be deployed', name: 'ARTIFACT_VERSION'
    }
    stages {
        stage('Initialization') {
            steps {
                echo 'Initializing'
                script {
                    currentBuild.displayName = "#${BUILD_NUMBER} - ${params.ENVIRONMENT_NAME} - ${params.SERVER_GROUP_NAME} - ${params.ARTIFACT_VERSION}"
                    currentBuild.description = "Deploying ${params.ARTIFACT_VERSION} to ${params.SERVER_GROUP_NAME} in ${params.ENVIRONMENT_NAME}"
                }
            }
        }
        stage('Download Artifacts') {
            steps {
                echo "Downloading ${params.ARTIFACT_VERSION} Artifacts"
            }
        }
        stage('Deploy Artifacts') {
            steps {
                echo "Deploying ${params.ARTIFACT_VERSION} Artifacts to ${params.SERVER_GROUP_NAME} in ${params.ENVIRONMENT_NAME}"
            }
        }
    }
}

The sample pipeline demonstrates how to define parameters for environment, server group, and artifact version, and then set the build’s display name and description accordingly. This makes it easy to identify the purpose of each build at a glance.

Follow the author for more DevOps, Linux, and AWS related articles.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdautomationPipelineJenkinsBuild Naming
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.