如何区分Jenkins Pipeline中的构建触发器 [英] How to differentiate build triggers in Jenkins Pipeline
本文介绍了如何区分Jenkins Pipeline中的构建触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望为我的Jenkinsfile添加一个条件阶段,该阶段取决于生成的触发方式.目前,我们的设置可以通过以下方式触发构建:
I'm hoping to add a conditional stage to my Jenkinsfile that runs depending on how the build was triggered. Currently we are set up such that builds are either triggered by:
- 分支索引中获取的git repo更改
- 用户使用UI中的立即构建"按钮手动触发构建.
是否有任何方法可以运行不同的流水线步骤,具体取决于这些操作中的哪一个触发了构建?
Is there any way to run different pipeline steps depending on which of these actions triggered the build?
推荐答案
以下代码应可确定用户是否已启动管道或计时器/其他触发器:
The following code should works to determine if a user has started the pipeline or a timer/other trigger:
def isStartedByUser = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) != null
这篇关于如何区分Jenkins Pipeline中的构建触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文