Jenkins: 如何更新当前构建名称和描述

2022-12-29 17:14:58 浏览数 (1)

How to update the current build name and description.

Jenkins is a famous and mostly used CI tool and we are also using it for build and release and other automated jobs. We also have a deployment job that deploys the selected artifact version to selected server groups (similar to autoscaling groups in AWS) in the selected environment. The job is working as expected. By default, Jenkins set the build name as the build number (see the red color box in the below snapshot). what if somebody wants to know to which environment and server group 3rd or 4th build jobs deployed? In that case, we have to open the job details and needs to check. Jenkins 是一个著名的、最常用的 CI 工具,我们也用它来构建和发布以及其他自动化工作。我们还有一个部署作业,可将所选构件版本部署到所选环境中的选定服务器组(类似于 AWS 中的自动扩展组)。作业按预期工作。默认情况下,Jenkins 将构建名称设置为内部版本号(请参阅下面快照中的红色框)。如果有人想知道部署了哪个环境和服务器组的第 3 个或第 4 个生成作业,该怎么办?在这种情况下,我们必须打开作业详细信息并需要检查。

But for the 6th,7th, and 8th builds, by seeing the build details themselves without opening, we can get all the important details. This can be achieved by updating the currentBuild.displayName and currentBuild.description variables. 但是对于第 6、7 和 8 个构建,通过不打开即可查看构建细节本身,我们可以获得所有重要细节。这可以通过更新currentBuild.displayNamecurrentBuild.description变量来实现。 Sample template 示例模板:

代码语言:javascript复制
pipeline {
    agent any

    parameters {
        choice choices: ['develop', 'test', 'state', '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_VAERSION'
    }
    stages {
        stage('Initilization') {
            steps {
                echo 'Initilizating'
                script{
                    currentBuild.displayName = "#${BUILD_NUMBER} - ${params.ENVIRONMENT_NAME} - ${params.SERVER_GROUP_NAME} -${params.ARTIFACT_VAERSION}"
                    currentBuild.description = "Deploying ${params.ARTIFACT_VAERSION} to ${params.SERVER_GROUP_NAME} in ${params.ENVIRONMENT_NAME}"
                }
            }
        }
        stage('Download Atrifacts') {
            steps {
                echo "Downloading ${params.ARTIFACT_VAERSION} Atrifacts"
            }
        }
        stage('Deploy Atrifacts') {
            steps {
                echo "Deploying ${params.ARTIFACT_VAERSION} Atrifacts to ${params.SERVER_GROUP_NAME} in ${params.ENVIRONMENT_NAME}"
            }
        }
    }
}

I Hope, You liked this article. More articles related to DevOps tools, Linux and AWS on the way so please follow me for getting notifications. Bye for now

0 人点赞