6

I believe it's stupid question but I don't understand how should I use gitlab merge request push options

I have this scenario:

  • I have open merge request from develop to master
  • I make some changes on develop branch and push them to gitlab server with the proper option
git add .
git commit -m 'finish mr'
git push origin develop -o merge_request.merge_when_pipeline_succeeds
  • I expect that after pipelines of this commit will succeed the MR be merged but instead I get this message on gitlab MR page:
@user aborted the automatic merge because source branch was updated just now
@user added 1 commit just now

    8efdbde1 - finish mr

So it seems that the push will set MR to allow merge after succeed and immediately abort it because of commit from same push. I also tried quick actions with /merge but same result. I know there is gitlab API, but I can't use it. Does anyone know what I am doing wrong?

EDIT:

as accepted answer suggested adding target branch helped, but I also needed to add ci.skip:

git push origin $CI_COMMIT_REF_NAME \
-o ci.skip \
-o merge_request.target="$MASTER_BRANCH_NAME" \
-o merge_request.merge_when_pipeline_succeeds \
-o merge_request.create
Daniel Barton
  • 491
  • 5
  • 14

1 Answers1

2

You can see that error message updated in gitlab-foss commit 882e798, as part of issue 63187 and MR (Merge Request) 30249 for recent GitLab 12.1.

That merge_request.merge_when_pipeline_succeeds option comes from gitlab-foss MR 26752 (GitLab 11.10, April 2019), issue 43263 (release notes).
The MR includes:

To create a new merge request, set its target branch, and set it to merge when its pipeline succeeds:

git push -u origin -o merge_request.create \
  -o merge_request.target=branch1 \
  -o merge_request.merge_when_pipeline_succeeds

Updating existing merge requests

When pushing branches with an existing open merge request, target and merge_when_pipeline_succeeds can be used to update the merge request.

So in your case, maybe add the target:

git push origin develop -o merge_request.merge_when_pipeline_succeeds \
  -o merge_request.target=master
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Hi thanks for your answer. Sadly add target option does not help. I still get "aborted the automatic merge because source branch was updated just now". The only way I can successfully set 'merge_when_pipeline_succeeds' push option is when I also create the MR (-o merge_request.create) in same push, when no MR exists yet. So I can create MR with this option but I can't update existing one. Is it bug or is it feature? :) – Daniel Barton Oct 10 '19 at 12:34
  • @DanielBarton Probably a bug, which should means a new issue. – VonC Oct 10 '19 at 13:15
  • is it actually solved or not? Because i'm facing the same issue, 3 years later... – klapinski Feb 09 '22 at 15:59
  • @KamWo I don't think this has been solved yet. – VonC Feb 09 '22 at 21:20