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

How to update the current build name and description.

7d716879fdfe5ed039a8afeaf209ec8a.jpeg

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 个生成作业,该怎么办?在这种情况下,我们必须打开作业详细信息并需要检查。

9345c333c35474bebd33230a9326c715.png
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 示例模板:

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 😀.

我希望,你喜欢这篇文章。更多与DevOps工具,Linux和AWS相关的文章即将发布,因此请关注我以获取通知。暂时😀再见.


DevOps云学堂,一个盛满新技术实践的学习平台。技术开放交流,技术实践实施分享。目前课程正在进一步覆盖DevOps全流程!

173fb8829b6d95e6d1020c6cb99644bd.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值