I have a task to create a Jenkinsfile and set up Jenkins to trigger a build when a pull request is made into the Dev branch. I have searched extensively but couldn’t find the right approach to achieve this
I’m using a multi-branch pipeline, and from what I see, things are different. There will be one Jenkinsfile across all branches, and I need to specify that the build is triggered only for pull requests (PRs) targeting the DEV
branch
Also look here.
There are environment variables that can be read by Jenkinsfile so you can simply quit the build if not on the correct branch.
You should in the first instance create a jenkinsfile that just prints all the global environment and quits, then see how these change for PR/not PR and on different branches so see what the conditions you are looking for are.
Bottom line, you may not be able to prevent the pipeline triggering for any PR between any branches, but you can use logic inside the pipeline to decide whether to execute it all, or just quit early.