I have a Gitlab - Jenkins integration that works. When an MR is created on Gitlab, a build is triggered in Jenkins. This is done by a request sent by Gitlab to Jenkins where is a lot of information, including source and target branch.
The problem is that I could not find a way in Jenkins to read the source branch from there and because of that when an MR is created on Gitlab, Jenkins triggers and builds ALL branches with new commits since the last run. I a quiet repo, this would work, usually the branch from MR is the branch that was last pushed.
But, I now have a project with many pushes, hundreds of feature branches, many people are playing with that code and I do not want to ever build those branches. When and MR is created I want to only build the source branch of the MR.
How can I achieve that? I suspect that I should be able to somehow use the information from the request sent by Gitlab to Jenkins to fetch the source branch.
To sum up, when a MR is created in Gitlab, the build is triggered in Jenkins. But, the build finds all branches updated
07:10:46 Seen 529 remote branches
07:10:46 > git show-ref --tags -d # timeout=10
07:10:46 Multiple candidate revisions
07:10:46 Scheduling another build to catch up with MR_Builder
And is going to build all updated branches. I want to prevent that and build only the source branch of the MR that triggered the build
CodePudding user response:
Finally, I have it working. On the Source Code Management
section of the job in Jenkins, I had to specify Branches to build
, using variable from Gitlab, like this origin/${gitlabSourceBranch}
.
CodePudding user response:
A better way, no need hard code a specific branch: https://docs.gitlab.com/ee/integration/jenkins.html#configure-the-jenkins-project
You use trigger by merge request event, set it in all branches. Jenkins only build branch has merge event.