How do I configure Jenkins to trigger on a pull request based on the Git branchs name?

HOW TO -️ October 18, 2021

I want pull requests to Git where the target is master and the source has a string "foo" to trigger a Jenkins build.

If this string "foo" appears in the source branch's name when there is a pull request, I want the Jenkins build to start.

The only way I can think of doing something this sophisticated is to put the logic into a Jenkins pipeline file. Is there a plugin or supported way of making this work? I am not using Github.

Is there a way to filter any branch that does not have "foo" in it? How do I trigger a build based on a pull request? I tried doing this by itself (without the search for the pattern "foo"), and even that failed. There were no errors, but I know Jenkins was authenticating to Git with the credentials I configured in Jenkins. The Jenkins job would not run when the conditions I configured were met.

Answer

This depends a bit on which plugins you've got on the server - do you have access to this information?

Initializing...