jenkinsci / jenkinsci/gitlab-plugin

Merge when pipeline succeeds triggered before Jenkins build finishes

Open
#1,028 15 comments 1 reaction 1 assignee Claimed by @markjacksonfishing View on GitHub
needs verification/testing
Dominant language
Java
Stars
1.4k
Forks
615
Avg merge
4h 32m
Merged PRs (30d)
10

Description

### Context
- **Gitlab plugin version**: 1.5.13
- **Gitlab version**: 12.6.3
- **Jenkins version**: 2.204.2
- **Job type**: Multibranch pipeline

### Jenkinsfile
```
#!groovy

properties([
disableConcurrentBuilds(),
gitLabConnection('xxxxxx'),
buildDiscarder(logRotator(artifactNumToKeepStr: '1'))
])

gitlabBuilds(builds: ['Configure', 'Test', 'Package', 'Deploy', 'Report']) {
node('xxxxxx') {
catchError {
stage('Configure') {
gitlabCommitStatus('Configure') {
...
}
}

stage('Test') {
gitlabCommitStatus('Test') {
...
}
}

stage('Package') {
gitlabCommitStatus('Package') {
...
}
}

stage('Deploy') {
gitlabCommitStatus('Deploy') {
...
}
}

stage('Report') {
gitlabCommitStatus('Report') {
...
}
}
}

step([
$class: 'Mailer',
notifyEveryUnstableBuild: true,
recipients: emailextrecipients([[$class: 'CulpritsRecipientProvider']])
])
}
}
```

### Problem description

When using the "Merge when pipeline succeeds" button in GitLab, the MR will be merged after the first stage of the pipeline has finished, rather than waiting until the entire pipeline has finished.

i.e. it would be merged after the Configure stage in the Jenkinsfile above.

I think a possible mitigation would be to wrap the entire pipeline in an additional `gitlabCommitStatus() {}` block but I have not tested this.

This could be solved at a plugin level by automatically having a pipeline stage that encompasses the whole pipeline.

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.