Accepting MR Through Jenkins Returns 405 Method Not Allowed
Summary
When setting "Only allow merge requests to be merged if the build succeeds" and adding the option to accept an MR on Jenkins, the logs on Jenkins return a 405.
Steps to reproduce
-
Add Jenkins Integration via Project -> Integrations -> Jenkins CI
-
On GitLab, head to Project Settings and set Merge Requests to "Only allow merge requests to be merged if the build succeeds
-
On Jenkins:
- Under Build Trigger, select
Opened Merge Request Events
- In Post-Build Steps, select "Accept GitLab Merge Requests On Success"
- Under Build Trigger, select
-
Create MR on GitLab
-
You'll notice that the build is successful on Jenkins, although the Jenkins logs indicate a
405 Method Not Allowed
What is the current bug behavior?
The build runs on Jenkins and is successful, but the MR is not accepted via Jenkins because it returns a 405. The user is forced to accept the MR manually.
What is the expected correct behavior?
MR should be accepted by the Jenkins user
Relevant logs and/or screenshots
Notice the PUT
request in api_json.log
and "should_remove_source_branch","value":"false"
is set to false even though I have selected Only allow merge requests to be merged if the build succeeds
:
{"time":"2019-05-29T21:05:33.253Z","severity":"INFO","duration":60.61,"db":6.69,"view":53.92,"status":405,"method":"PUT","path":"/api/v4/projects/13/merge_requests/12/merge","params":[{"key":"merge_commit_message","value":"Merge Request accepted by jenkins build success"},{"key":"should_remove_source_branch","value":"false"}],"host":"gitlab.runner","ip":"107.170.247.131, 107.170.247.131","ua":null,"route":"/api/:version/projects/:id/merge_requests/:merge_request_iid/merge","user_id":1,"username":"root","queue_duration":8.98,"gitaly_calls":0,"correlation_id":"sOp2ixQlKw7"}
Note: When accepting the MR on GitLab, the api_json.log
show that should_remove_source_branch
is true
:
{"key":"commit_message","value":"Merge branch 'jenkins-branch' into 'master'\n\nJenkins branch\n\nSee merge request other-group/mvn!14"},{"key":"merge_when_pipeline_succeeds","value":true},{"key":"should_remove_source_branch","value":true}
Jenkins build logs:
Failed to accept merge request for project '12': HTTP 405 Method Not Allowed Finished: SUCCESS
Possible fixes
Not sure which line of code is responsible, but given the difference between the accepting the MR via the UI on GitLab vs accepting via the API, I believe this is linked to the value of "should_remove_source_branch"
being set to false
(If you can, link to the line of code that might be responsible for the problem)