How to toggle "merge when pipeline succeeds" via GitLab API


#1

Hi All,

Actually my first post on the forums, so please let me know if something is not ok.

so here goes :

I would like to set the “Merge when pipeline succeeds” flag while a pipeline is running (imagine it being the last step after all build / test has been completed). The method of doing so would be via the Gitlab API (V3/V4).

what i want is to flag this “button” in the interface of a Merge Request:

This is the same button which transforms into a green “Accept Merge Request” button when a pipeline succeeds (screenshot has been made afterwards to avoind confusion):

Furthermore i have set the follwing setting in general Settings according to the documentation:

nRICr

According to the Gitlab API documentation I should use the following endpoint in for flagging this feature:

PUT /projects/:id/merge_requests/:merge_request_iid/merge

when using the parameter ?merge_when_pipleline_succeeds=true it should flag the button.

However when i call this endpoint v(ia a powershelll wrapper) when the pipeline is still running (i built in a wait for 10 mins while testing this) i get the following result:

i am getting a Method Not Allowed. My assumption is that the endpoint i am using is correct because otherwise i would’ve gotten a bad request / not found return code.

when checking the gitlab merge request i am seeing that indeed the flag is not set to true:

However, when i manually click the blue button the mergerequest looks like this:

Also if i let the pipeline finish and then proceed to call the merge api (w/ or w/o the merge when pipeline succeeds flag) it will accept the merge. It just does not work when the pipeline is running (which is odd because even the button itself only shows when the pipeline is running)

so i am wondering what I am doing wrong here.

I am using the same credentials for the API w/ a personal access token to authenticate to the API. Other functionality of the API work with this token like creating merge requests, retrieving status of a current MR and accepting a MR when the pipeline is finished. The MR for which i want to flag this feature was also made via the API with the same token / credentials.

I have tried the following variants :

  • Use the V3 api with merge_when_build_succeeds=true --> nets the same result
  • Uncheck the “Only allow merge request to be merged if the pipeline succeeds” --> nets the same result
  • Use ID of the merge request instead of IID
  • use /merge_when_pipeline_succeeds instead of ?merge_when_pipeline_succeeds=true
  • use True instead of true --> nets the same result

So i’m a bit lost on why the API gives me this result even though other features appear to be executing as normal.

Thoughts / suggestions ? also if you feel i missed out on information let me know. I’m happy to provide more if needed.


#2

Have the same issue, was you successful with it?


#3

Hi Victor,

I am still facing the same issues. No luck here. Also posted a topic on Stackoverflow but no replies there either.

If you find a solution obviously i am interested in it.

Regards,

Tobi


#4

Ok, sure, I will let you know


#5

Did you figure out a solution for this? I’m having exactly the same issue. One would expect the api provides at least the same functionality as pushing the “merge when pipeline succeeds” button.