Open TonyNoble opened 3 years ago
+1
I am encountering the same issue.
The last_commit makes sense if the merge is a fast forward. In the case where the merge creates a merge-commit, the SCM checkout should use the object_attributes.merge_commit_sha
.
If for whatever reason checking out the code at object_attributes.merge_commit_sha
is not possible, provide the object_attributes.merge_commit_sha
as an env variable so we can check the code out ourselves.
This option works sh "git branch --set-upstream-to=origin/${env.gitlabTargetBranch} ${env.gitlabTargetBranch} && git pull"
however in the case where many merge requests gets merged in the span of few seconds, object_attributes.merge_commit_sha
and git pull
will not be the same commit id.
Version report
Jenkins and plugins versions report:
Reproduction steps
Results
Expected result:
The latest commit of the target branch is checked out into a local branch with a matching name
Actual result:
The latest commit of the source branch is checked out into a local branch that matches the target branch name
Diagnosis / workaround:
This would appear to be due to the way the webhook from gitlab is handled - the "last_commit" details in the hook are actually those of the head of the branch being merged in. The resulting merge commit sha is actually sent through in the object_attributes.merge_commit_sha field, but it is "last commit" that is checked out and as such the local branch ends up one commit behind the the remote. This causes particular problems when trying to run maven releases - these fail with an error.
The workaround is to add the following as a secondary step after the checkout:
However this feels like a hack - shouldn't a completed merge request check out the full result of the merge?