计时器触发作业时如何在Jenkins中获取BUILD_USER? [英] How to get the BUILD_USER in Jenkins when job triggered by timer?
问题描述
我想在职位招聘电子邮件中显示触发了Jenkins职位的用户.这可以通过使用插件 Build User Vars插件和env变量BUILD_USER
来实现.
但是在由调度程序触发作业时,不会初始化此变量.
I wanted to show the user who triggered a Jenkins job in the post job email. This is possible by using the plugin Build User Vars Plugin and the env variable BUILD_USER
.
But this variable do not get initialized when the job is triggered by a scheduler.
我们如何实现这一目标?我知道我们有一个名为EnvInject插件的插件,可以使用...
How can we achieve this? I know we have a plugin called - EnvInject Plugin, and that can be used...
但是我只想知道我们如何使用它并实现解决方案...
But I just want to know how we can use this and achieve the solution...
推荐答案
这可以使用Jenkins Build User Vars Plugin
完成,它公开了一组环境变量,包括启动构建的用户.
它提供了环境变量,例如BUILD_USER_ID,EMAIL等.
This can be done using the Jenkins Build User Vars Plugin
which exposes a set of environment variables, including the user who started the build.
It gives environment variables like BUILD_USER_ID, EMAIL, etc.
当登录用户手动触发构建时,该用户的用户ID在BUILD_USER_ID
环境变量中可用.
When the build is triggered manually by a logged-in user, that user's userid is available in the BUILD_USER_ID
environment variable.
但是,当Jenkins计时器/调度程序自动触发构建时,不会替换/初始化此环境变量.
However, this environment variable won't be replaced / initialized when the build is automatically triggered by a Jenkins timer / scheduler.
附加了屏幕截图以获取详细信息
Attached a screenshot for details
这可以通过使用条件构建步骤插件/运行条件插件向作业中注入条件来解决,其中,在每个作业中,我们仅在由构建引起或触发构建时才可以添加条件以初始化变量BUILD_USER_ID.计时器或调度程序,通过使用正则表达式设置条件..
This can be resolved by injecting a condition to the Job by using Conditional Build Step Plugin / Run Condition Plugin,where in to each job we can add a condition to initialize the variable BUILD_USER_ID only when the build is caused or triggered by the Timer or scheduler, by setting a condition using the regular expression..
这篇关于计时器触发作业时如何在Jenkins中获取BUILD_USER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!