您可以使用Build Name Setter Plugin 根据可用令牌更改名称。
我不确定您的 Git 分支名称是否存在 TOKEN,但如果一切都失败了,您可以使用 shell 脚本构建步骤并将其写入属性文件,然后使用宏:${PROPFILE,..} ,例如:
#${BUILD_NUMBER}_${PROPFILE,file="parameters.properties",property="BUILD_TYPE"}
或者,您可以使用Description Setter Plugin 根据构建输出更改构建描述(也显示在构建执行器状态中)。同样,您可以使用相同的技巧并使用 shell 脚本在构建输出中打印出分支名称,并使用正则表达式将其从构建日志中解析出来。
一个小限制:其中任何一个都只会在作业完成后更新名称/描述,因此对于长时间运行的作业,它不会立即可见。但对于简短的,以及出于审计目的,这很有效。
[编辑]
一段时间后,我开始使用EnvInject plugin,它足够早地将我的构建参数添加到环境中,以便Build Name Setter Plugin 使用它们。
这样做的好处是可以立即设置构建名称。
另外,您可以使用 ${GIT_BRANCH} 获取 Git 分支。这是它的文档:
${GIT_BRANCH}
Expands to the name of the branch that was built.
Parameters:
all
If specified, all the branches that point to the given commit is listed.
By default, the token expands to just one of them.
fullName
If specified, this token expands to the full branch name, such as 'origin/master'.
Otherwise, it only expands to the short name, such as 'master'.