how to build on branch creation but not build on other scm event/commit?

23 views
Skip to first unread message

Tim Black

unread,
Sep 17, 2020, 12:59:27 AM9/17/20
to Jenkins Users
1. I have a multibranch pipeline job that takes 30min to run, has a lot of branches, and my company is still at the earlier stages of devops transformation, so with our current infrastructure we do not want to trigger a build every commit.

2. Our job pipeline uses parameters heavily, so I would also like to automatically build each branch on branch creation/detection. 

How do I achieve the above 2 requirements?

Using git scm/plugin/branchsource, if I set (or clear) "Suppress Automatic SCM triggering", I get only one of the two requirements fulfilled: setting it suppresses ALL automatic triggering, not providing 2. Clearing it satisfies 2, automatically triggering a build on branch discovery, but also builds every commit which we don't want.

In my research I have found the basic branch build strategies plugin, and while it provides some great sophisticated control over what branches build when, in terms of ensuring the job is built on branch creation, it seems to only provide added suppression.

Any suggestions would be welcome. Thanks.

jeremy mordkoff

unread,
Sep 17, 2020, 12:12:17 PM9/17/20
to Jenkins Users
You could leave the Automatic triggering suppressed and write a tool to scan your GIT repo looking for new branches and trigger the build via an API call when a new branch is found. Sounds like you might need such a tool anyway so that developers could schedule builds. 

Tim Black

unread,
Sep 17, 2020, 3:33:23 PM9/17/20
to Jenkins Users
Thanks Jeremy. Our developers already have control of their projects' branches' Jenkinsfiles so they can define whatever triggers/schedule they want. If I were going to hack this, I'd probably prefer to do the opposite of what you're recommending. Since git scanning is a wheel already invented many times, I'd rather NOT "Suppress Automatic SCM Triggering", but modify our pipelines (Declarative Jenkinsfile + loaded groovy file(s)) to check the "build cause" and act accordingly. Ultimately, we're likely to need this kind of sophistication anyway, since some build causes ( e.g. Branch Discovery, PR, commit, etc) may need special behavior. Ultimately ultimately, we'll have more build capacity and will be able to support per-commit builds, so perhaps some of this is temporary.

We're using Bitbucket On Prem, FWIW, and soon I will be implementing various Jenkins-Bitbucket integrations. Currently we're still just using Jenkins git plugin as BranchSource for our multibranch pipeline jobs. Perhaps once I switch us over to using the Bitbucket Server Integration plugin, a more elegant solution to this fine control over Automatic SCM Triggering will become clear.

Cheers.

Reply all
Reply to author
Forward
0 new messages