【问题标题】:How to graphically visualize/tag build branch in Jenkins?如何在 Jenkins 中以图形方式可视化/标记构建分支?
【发布时间】:2017-06-29 13:47:01
【问题描述】:
我正在构建 Jenkins 构建管道,我想知道是否有可能以某种方式在 Jenkins 中标记/可视化构建分支,就像在 TeamCity 中自动实现的那样。
我正在使用在单独的 git 存储库和 Jenkins 2.46.3 中定义的声明式管道。
从图片上看,最后 2 个构建是在单独的分支上执行的并不明显:
谢谢
【问题讨论】:
标签:
jenkins
jenkins-plugins
jenkins-pipeline
【解决方案1】:
您可以使用以下代码修改当前构建的显示名称和描述:
currentBuild.displayName = env.BRANCH_NAME
currentBuild.description = 'Final Release'
这是最近在BlueOcean 1.1 announcement 中突出显示的,它显示了两者,而常规界面仅显示displayName。
从our public instance 修改的displayName 示例如下所示:
您可以在我们的共享库here 和here 中找到生成此代码的代码,本质上是:
currentBuild.displayName = "#${currentBuild.getNumber()} - ${newVersion} (${increment})"
正如您提到的声明性管道,让我们补充一下,您当然必须将此代码包装在script 块中。所以可能(未经测试):
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Hello World'
script {
currentBuild.displayName = env.BRANCH_NAME
}
}
}
}
}
或者,您可以将其提取到单独的函数中。