如何区分 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 所做的更改,这些更改是在分支索引中获取的
- 用户使用界面中的立即构建"按钮手动触发构建.
有没有办法根据这些操作中的哪一个触发构建来运行不同的管道步骤?
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屋!
查看全文