groovy 当一个人重建一个由计时器触发的作业时,如何在Jenkins中获得BUILD_USER?

qzwqbdag  于 2022-11-21  发布在  Jenkins
关注(0)|答案(1)|浏览(211)

编辑:我用这个插件来安排运行btw:https://plugins.jenkins.io/parameterized-scheduler/
我已经设置了空闲时间通知,当计时器(调度程序)开始执行时,它将自动发送。
在空闲通道中,当自动构建开始时,它将发布类似以下内容的内容:

(/ci/master-15): Started by timer with parameters: {URL=https://shop.com, USERNAME=yyy, PASSWORD=xxs, SLACK-NOTIFY-CHANNEL=#JENKINS-REPORTS}

当运行完成时,类似于以下内容的消息将发布到通道:

(/ci/master-15): The job is now complete. Here are the execution summary

好极了:

BUILD_TRIGGERED_BY = currentBuild.getBuildCauses().shortDescription[0]
SEND_SLACK_NOTIF(BUILD_TRIGGER_BY)

现在,如果一个人在这些计时器作业失败后重建它们之一,我希望它会说“Started by andrea-hyong@gmail.com“,但是
在管道状态中,它显示:

Started by timer with parameters: {URL=https://shop.com, USERNAME=yyy, PASSWORD=xxs, SLACK-NOTIFY-CHANNEL=#JENKINS-REPORTS}

Started by user andrea-hyong@gmail.com

Rebuilds build #14

在时差消息中,它显示:

Started by timer with parameters: {URL=https://shop.com, USERNAME=yyy, PASSWORD=xxs, SLACK-NOTIFY-CHANNEL=#JENKINS-REPORTS}

如何让它发送用户名而不是计时器?

e4yzc0pl

e4yzc0pl1#

您看到的行为是您使用的插件的结果。我假设rebuild插件在重建作业时选择了两个触发器。由于您在重建时有一致的行为,您可以改进您的Groovy代码,使其类似于下面的代码。

BUILD_TRIGGERED_BY = currentBuild.getBuildCauses().shortDescription.size() > 1 ?  currentBuild.getBuildCauses().shortDescription[1] : currentBuild.getBuildCauses().shortDescription[0]

相关问题