We are migrating our gitlab projects to AzureDevOps.
Currently, our projects in gitlab are configured with a webhook, which triggers a jenkins build on every commmit.
The jenkins build pipeline is written in groovy, and has a different flow when it comes to merge requests. We make use of the branch name in the following manner: ( if (env.BRANCH_NAME ==~ /MR-.*/) { do some checks }
In our first step of migration, we plan to move away from gitlab to azure git. The commits to azure repos should still trigger the jenkins.
I am not having an idea as to how to deal with merge requests. Currently, I see that there is no branch created while creating a PR in azure. As a result I cannot make use of ( if (env.BRANCH_NAME ==~ /PR-.*/) { do some checks }
Any suggestions to work around this?
2
Answers
It’s been a long time since I used Jenkins in anger so I can’t remember what environment variables are available. However the branch name for a pull request will be
merge
The full "path" to the branch will look something like
refs/pull/123/merge
where123
is the pull request number.Note that this information comes from the Azure Pipeline docs so YMMV in Jenkins (look for Build.SourceBranch)
Looking at our own builds (we use Azure DevOps Pipelines), pull request branches look like:
Notice the
refs/pull/{PR-ID}/merge
pattern.Also, for the webhook trigger, you probably would need to utilize the "Pull request merge attempted" event:
Hope it helps,