简体   繁体   English

当与多个git repos一起使用时,如何防止Jenkins管道(工作流)触发多个构建?

[英]How do I prevent Jenkins pipeline (workflow) from triggering multiple builds when used with multiple git repos?

If you have a workflow which uses multiple git repositories, each git push triggers a build in Jenkins. 如果您有一个使用多个git存储库的工作流,则每个git push都会触发Jenkins中的构建。

If I have a workflow job configured to poll 10 git repositories and I pushed changes to all of them [quite possible when doing a release build] - that's 10 builds in the queue. 如果我将工作流作业配置为轮询10个git存储库,并且我将更改推送到所有这些[很可能在执行发布版本时] - 那就是队列中的10个构建。 This is both good and bad. 这既好又坏。 Bad because we will have changes in different repositories and we would like to kick off the build once all the files are in. At the same time I don't want to avoid polling the repositories. 不好,因为我们将在不同的存储库中进行更改,并且我们希望在所有文件都进入后启动构建。同时我不想避免轮询存储库。

stage 'REPO-1' { 阶段'REPO-1'{
git branch: "feature/testbranch", changelog: true, poll: true, url: 'ssh://git@stash.com/repo1.git', credentialsId: 'xxx' } git branch:“feature / testbranch”,changelog:true,poll:true,url:'ssh://git@stash.com/repo1.git',credentialsId:'xxx'}

stage 'REPO-2' { 阶段'REPO-2'{
git branch: "feature/testbranch", changelog: true, poll: true, url: 'ssh://git@stash.com/repo2.git', credentialsId: 'xxx' } git branch:“feature / testbranch”,changelog:true,poll:true,url:'ssh://git@stash.com/repo2.git',credentialsId:'xxx'}

Is there a way I can prevent this behavior perhaps introduce a delay in polling. 有没有办法可以防止这种行为或许会导致轮询延迟。

Have you considered using Additional Behaviours: Polling ignores commits with certain messages ? 您是否考虑过使用Additional Behaviours: Polling ignores commits with certain messages

If set, and Jenkins is set to poll for changes, Jenkins will ignore any revisions committed with message matched to Pattern when determining if a build needs to be triggered... 如果设置,并且Jenkins设置为轮询更改,Jenkins将在确定是否需要触发构建时忽略与Pattern匹配的消息所提交的任何修订...

Steps: 脚步:

  1. Commit your changes with IGNORE message. 使用IGNORE消息提交更改。
  2. Once all repositories are up to date, then trigger build manually or with no-IGNORE message. 一旦所有存储库都是最新的,则手动触发构建或使用no-IGNORE消息触发构建。

Checkout step: 结帐步骤:

checkout([$class: 'GitSCM', 
    branches: [[name: '*/master']], 
    doGenerateSubmoduleConfigurations: false, 
    extensions: [[$class: 'UserExclusion', excludedUsers: ''], 
    [$class: 'MessageExclusion', excludedMessage: '.*\\[ignore-this-commit\\].*']], 
    submoduleCfg: [], 
    userRemoteConfigs: [[url: 'https://github.com/luxengine/math.git']]])

I have enabled quiet period option and added a timeout of 60 seconds. 我启用了静默期选项并添加了60秒的超时。 This will help Jenkins workflow to collapse changes to multiple repositories within a quiet period into one and trigger single build instead of triggering multiple builds for every SCM change. 这将有助于Jenkins工作流将在一个安静时期内对多个存储库的更改折叠为一个并触发单个构建,而不是为每个SCM更改触发多个构建。 在此输入图像描述

Keep in mind that the quiet period in my case is set to 60 seconds, as long as the other changes are within 60 seconds it will add another 60 seconds quiet period to watch for any other changes in the repositories. 请记住,我的情况下的静默期设置为60秒,只要其他更改在60秒内,它将再添加60秒静默期以监视存储库中的任何其他更改。 But If you make another change to the repository after 60 seconds it will be another build. 但是如果你在60秒后对存储库进行另一次更改,那将是另一个构建。

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

相关问题 Jenkins Multibranch Pipeline触发来自多个SCM存储库的构建 - Jenkins Multibranch Pipeline triggering builds from multiple SCM repos 防止 Jenkins 多分支管道触发新分支的构建 - Prevent Jenkins multibranch pipeline from triggering builds for new branches 在一个 jenkins 管道中管理多个微服务 git repos - Manage Multiple Microservices git repos in one jenkins pipeline 使用 Jenkins 管道将多个 git 存储库检出到同一个作业中 - Using a Jenkins pipeline to checkout multiple git repos into same job 使用 Jenkins 管道将多个 git 存储库检出到子目录中 - Using a Jenkins pipeline to checkout multiple git repos into subdirectories 如何从一个本地 git 存储库获得多个 Jenkins 构建? - How can I get multiple Jenkins builds to work from one local git repo? Jenkins 管道:如何将它们与 Git 一起使用,尤其是与多个 Git 存储库一起使用? - Jenkins pipelines: How to use them with Git, especially with multiple Git repos? Jenkins Git Publisher,多个repos和Multiple SCM - Jenkins Git Publisher, multiple repos and Multiple SCM 如果以后构建“超车”,我如何防止 Jenkins 中止构建? - How do I prevent Jenkins from aborting builds if later builds “overtake”? 如何将多个git repos克隆到Jenkins的同一工作区文件夹中 - How to clone multiple git repos into the same workspace folder in Jenkins
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM