繁体   English   中英

Jenkins:我怎么知道是自动流程还是用户触发了构建?

[英]Jenkins: How can I know if an automatic process or a user has triggered a build?

Jenkins 中是否有环境变量告诉我构建是手动运行还是由轮询自动触发?

如果自动触发,我的管道就像一个魅力,但如果手动运行......它总是失败,所以我想我将编辑管道以检查构建是如何触发的。

不幸的是,变量env.BUILD_CAUSE未在流水线构建中设置。 对于管道作业,请参见以下示例

if ( currentBuild.rawBuild.getCauses()[0].toString().contains('UserIdCause') ){
    // do steps for manual trigger here
}

其他可能的比较原因可以在这里找到。

获取工作流运行原因的功能已在版本 2.22(2018 年 11 月 2 日)中发布到管道支持 API 插件。 该功能是在 JENKINS-41272 中请求的。

该版本的 currentBuild 全局变量中添加了几个方法:

getBuildCauses

    Returns a JSON array of build causes for the current build

EXPERIMENTAL - MAY CHANGE getBuildCauses(String causeClass)

    Takes a string representing the fully qualified Cause class and returns a JSON array of build causes filtered by that type for the current build, or an empty JSON array if no causes of the specified type apply to the current build

请参阅答案https://stackoverflow.com/a/53342374/5955565 我已将其复制粘贴到此处,因为此问题首先显示在搜索结果中(与如何区分 Jenkins Pipeline 中的构建触发器不同)。

另请参阅${YOUR_JENKINS_URL}/pipeline-syntax/globals以获取 currentBuild 上可用的完整属性列表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM