Jenkins multibranch pipeline triggering build only for new commits - jenkins

I would like to use the multibranch pipeline functionality offered by Jenkins with some projects that have been around for long time, with a lot of branches.
I am using it in conjunction with the Basic Branch Build Strategies Plugin and the Multibranch Scan Webhook Trigger.
Since the projects have a lot of branches I would like to just index the branches when the multibranch pipeline is triggered and run the actual pipeline for a branch only when a new commit is pushed (The Multibranch Scan Webhook Trigger is used to notify the multibranch pipeline).
I have noticed the option "Skip initial build on first branch indexing" provided by the Branch Build Strategies Plugin which looked perfect at first: the branch is just indexed and the build is not triggered the first time.
The only issue is that the same goes for every new branch that gets created whereas I would like this option to be active only for the old branches.
The "Tags" option of the Branch Build Strategies Plugin has a "Ignore tags older than" parameter... a parameter like that for the "Skip initial build on first branch indexing" option would cover my use case but unfortunately there are no parameters available for it.

Related

Jenkins Multibranch Pipeline: Differentiate between build triggered by branch indexing vs webhook

I have a Jenkins multibranch pipeline for github and currently it triggers builds whenever a branch is indexed. I have certain actions in my pipeline that I only want triggered whenever there are changes to a branch (on a webhook push). So I was wondering if there's a Jenkins environment variable that will allow me to distinguish between the two different type of builds. Or if there's a git solution to check when the last change was made to the branch and differentiate it that way

Jenkins being run on all branches in repo instead of only the branch changed

I am pretty new to Jenkins, and when I make a pull request, the Github webhook triggers a rebuild on all branches in the repo. However, I only want the branch associated with the pull request to be built. I suspect that all branches are built due to nothing specified in the "Branch specifier."
Is there a way to specify to build only the branch the pull request was made to?
Thanks!
To resolve your issue try to use multibranch pipeline job or use filter in simple pipeline job.
To use multibranch pipeline job you need to install Pipeline: Multibranch plugin.
Pipeline job example
In simple pipeline job choose "Build when a change is pushed to GitLab" in "Build trigger" section -> Advanced -> Filter branches by name

Is there a way to have jenkins only automatically trigger a build for new PRs?

I am using Jenkins pipelines and the Bitbucket plugin
I can Suppress automatic SCM triggering but that suppresses everything
Is there a way to have Jenkins track all my branches, PRs, and tags in the multibranch pipeline but only automatically trigger a build for new PRs and not branches or tags? But still have it possible to manually trigger a build of any branch or tag.
I could have logic in the pipeline that exits if the build is not user initiated and is not a PR- but is there a config option to do that sort of thing for me?

Polling ignores commits in certain paths in multibranch pipeline

I have a multibranch pipeline with a project that I want to build only if there are changes in a specific directory.
I know that the Polling ignores commits in certain paths option can do exactly that but I can't find this option in the multibranch configuration.
Is this even possible for multibranch pipeline?
Theoretically, you can call the GitSCM class with an includedRegions path restriction in the checkout step (e.g. see here for the syntax).
However, this is not working with pipelines, as I just checked it last week. So unfortunately, Jenkins is really not well-suited for monorepos.

Jenkins Multi-Branch Project Plugin select two branches

I want to use the Jenkins Multi-Branch Project Plugin to select just two Git branches to build consistently. My branches are named development and SIT. I cannot guarantee the names of any other branch. In the downstream job created, I would like the branch name in the Git configuration to be:
*/development or */SIT
so that the Github trigger can work. There may be another configuration here that can make the Github trigger work, but this is the one I use for now.
I have tried:
:(development|SIT), (development|SIT), development,SIT development|SIT
all to no avail.

Resources