1
Jenkins在历史中展示构建者和分支名
source link: https://blog.51cto.com/liuzhiren/10510809
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
1、安装插件
“系统管理->插件管理” build user vars和Groovy Postbuild
2、jobs配置项
勾选Set jenkins user build variables这个选项后,在构建过程中会增加当前登录用户的如下信息到环境变量中,可以通过Groovy脚本获取这些变量值。变量名如下:
BUILD_USER 全名
BUILD_USER_FIRST_NAME 名字
BUILD_USER_LAST_NAME 姓
BUILD_USER_ID jinkins用户ID
BUILD_USER_EMAIL 用户邮箱
manager.addShortText() 函数用于在构建历史中添加额外的展示信息。
manager.getEnvVariable("BUILD_USER") 函数用于获取环境变量“BUILD_USER”,这个环境变量是“user build vars plugin”插件设置进去的(需要勾选“Set jenkins user build variables”)。
manager.build.buildVariables.get("branch") 函数用于获取“构建参数branch"的值,如果配置了“参数化构建”,通过这个函数可以获取构建时传入的参数
注意:branch这个是从前面参数化构建选项自定义的名字
3、jobs参数化构建示例:
pipeline参数如下:
// 打印tag和构建人信息
stage('modify attr') {
steps {
wrap([$class: 'BuildUser']) {
buildName "#${BUILD_NUMBER}-${BUILD_USER}-${ServerNum}"
buildDescription "Branch:${branch}"
}
}
}
实际效果如下:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK