1
votes

If you have a workflow which uses multiple git repositories, each git push triggers a build in 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. 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' {
git branch: "feature/testbranch", changelog: true, poll: true, url: 'ssh://[email protected]/repo1.git', credentialsId: 'xxx' }

stage 'REPO-2' {
git branch: "feature/testbranch", changelog: true, poll: true, url: 'ssh://[email protected]/repo2.git', credentialsId: 'xxx' }

Is there a way I can prevent this behavior perhaps introduce a delay in polling.

2

2 Answers

0
votes

Have you considered using 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...

Steps:

  1. Commit your changes with IGNORE message.
  2. Once all repositories are up to date, then trigger build manually or with no-IGNORE message.

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']]])
0
votes

I have enabled quiet period option and added a timeout of 60 seconds. 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.enter image description here

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. But If you make another change to the repository after 60 seconds it will be another build.