Best approach for trigger build only new added branches when scan multi-branch pipeline

16 views
Skip to first unread message

BTH

unread,
Sep 16, 2020, 5:07:39 AM9/16/20
to Jenkins Users
Dear folks,

I have a limited resources Jenkins server and a bunch of multi-branch pipelines which are poll from GitLab repositories (scripted jenkins pipeline ).

Then I've noticed that my Jenkins usually crash by run out of memory when someone click on scan multi-branch and its triggers build multiple pipelines at the same time.

My desired is only trigger automatically build the pipeline for only new added branch.
Right now I have master, hot-fix, release, support, develop and loads of features branches.
(The feature branches are frequently added)   

Then I searched for a solution, 'Suppress automatic scm triggering'  might help me. But it will block only the specific branch that we've set in the Jenkins's configuration rather than build new whatever added branch (it can be feature, support or any custom created branches). I don't want to strict the build with a specific branch.

So I came here for find the best approach for this issue. Any suggestions are welcomed

Thanks!

Gianluca

unread,
Sep 16, 2020, 5:35:12 AM9/16/20
to Jenkins Users
I can see some ways to achieve that.
You can look at the "triggeredBy" option to use in the "when" block to avoid build the pipeline is not triggered but what you want.
For example, we do this:

when {
  anyOf {
     triggeredBy 'UpstreamCause'
     triggeredBy 'UserIdCause'
  }
}

Because we don't want that pipeline to run on scan multi-branch, push commits and other things.

If there isn't any trigger that fits your case, then you can still create a little Groovy script that returns a boolean and use inside the when anyway like that:

when {
  expression {
    FSTChangePatterns.any{pattern -> sideCars.areFilesChanged(pattern)}
  }
}

I don't know other ways to achieve what you want but they may be there are.

Cheers,
Gianluca.
Reply all
Reply to author
Forward
0 new messages