jenkinsci / jenkinsci/gitlab-plugin

Accepting a merge request on Jenkins returns 405 not allowed

Open
#954 1 comment 5 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.4k
Forks
615
Avg merge
4h 32m
Merged PRs (30d)
10

Description

## Issue
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.
[](url)
### Context
- **Gitlab plugin version**: 11.9.6-ee
- **Gitlab version**: 1.5.12
- **Jenkins version**: 2.164.3
- **Job type**: Freestyle

### Logs & Traces
![Screen_Shot_2019-05-29_at_2 49 15_PM](https://user-images.githubusercontent.com/9112209/61724408-c0ffe580-ad22-11e9-8e08-882dc085a079.png)
![Screen_Shot_2019-05-30_at_10 13 38_AM](https://user-images.githubusercontent.com/9112209/61724458-df65e100-ad22-11e9-9bb6-0b23bf1b579c.png)

### Problem description
- Attempting to make Jenkins accept an MR if a build is successful
- Accept an MR via Jenkins
- Jenkins tries to accept the MR but a 405 is returned. This also means that when selecting `Delete source branch when merge request is accepted`, the branch needs to be deleted manually.

### Steps to reproduce:

1. Add Jenkins Integration via Project -> Integrations -> Jenkins CI
1. On GitLab, head to Project Settings and set Merge Requests to "Only allow merge requests to be merged if the build succeeds
1. On Jenkins:
* Under *Build Trigger*, select `Opened Merge Request Events`
* In *Post-Build Steps*, select "Accept GitLab Merge Requests On Success"
1. Create MR on GitLab
1. You'll notice that the build is successful on Jenkins, although the Jenkins logs indicate a `405 Method Not Allowed`

The `api_json.log` shows this:

`{"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"}`

Notice that `should_remove_source_branch` is set to false, even though I clicked on `Delete source branch when merge request is accepted.`

When accepting the MR via the UI (not Jenkins), I see that the value is set to 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}` \`

According to one of our engineers, this is may be due to the check that happens here: https://gitlab.com/gitlab-org/gitlab-ce/blob/c7e5d046a54cd10145ea81983a7e3ceb94755f79/lib/api/merge_requests.rb#L374

He also pointed out that the `should_remove_branch` is overriding the default value by setting it to `false` here:

https://github.com/jenkinsci/gitlab-plugin/blob/4231c220b578ad3511cde439f150f3f0ad6ef184/src/main/java/com/dabsquared/gitlabjenkins/gitlab/api/impl/V4GitLabApiProxy.java#L121

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.