gpt4 book ai didi

jenkins - 限制 Jenkins 管道构建哪个分支?

转载 作者:行者123 更新时间:2023-12-04 01:24:19 35 4
gpt4 key购买 nike

我目前正在配置托管在 AWS 中的 Docker 容器上的 Jenkins 服务器。

我正在使用 BlueOcean 配置存储库。

现在,管道扫描存储库上的所有分支以检测 Jenkinsfiles,然后如果检测到更改将自动在该分支上构建。我每 5 分钟扫描一次 repo 以检测更改。

但是,如果它是某个随机功能分支,我不想自动运行构建和作业。我试图将自动触发的构建限制为仅在 staging 和 master 分支中发生变化。

所以我的问题是,您如何/在哪里配置 Jenkins GitHub 管道以仅在某些分支上构建而不是扫描所有分支?

最佳答案

多分支管道作业是您的 friend 。

而不是试图限制 Jenkins 首先轮询哪些分支,我在我的 Jenkinsfile 中所做的是每分钟轮询源代码控制:

triggers { pollSCM('* * * * *') }

这将轮询每个分支并创建一个作业,它会在您在 Multibranch Pipeline 作业配置中指定的位置和名称中找到一个 Jenkinsfile。

Side Note

About the only configuration in a multibranch pipeline is:

  1. Where's the SCM repo?
  2. Workspace relative path and name of Jenkinsfile. (You can call it Bob if you want)


多分支管道作业设置了一个额外的环境变量:BRANCH_NAME,它允许您有条件地在管道中执行操作,如下所示:
script {
if( "${env.BRANCH_NAME}" == "integration" ) {
//Do something useful
}
}

使用此方法,您还可以决定不响应轮询事件。

关于jenkins - 限制 Jenkins 管道构建哪个分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52821516/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com