Auto-Merge executes before MR pipeline finishes when using Jenkins integration

Issue: Auto-Merge triggers prematurely before MR pipeline completion

I am experiencing an issue with the “Set to auto-merge when pipeline succeeds” feature in GitLab.

We have integrated Jenkins pipelines for both Merge Requests (MR) and the main branch. In GitLab, we have enabled the setting:
Settings → Merge Request → “Pipelines must succeed”.

The process works correctly when using the manual Merge button:

  • When I create a merge request, GitLab triggers the Jenkins pipeline for the MR.
  • Once the pipeline completes successfully, the Merge button becomes available.
  • Clicking it launches a separate Jenkins pipeline for the main branch.
  • This works perfectly — the MR cannot be merged until the MR pipeline finishes.

However, when I use the “Set to auto-merge” button, something goes wrong:

  • While the MR pipeline is running, I click Set to auto-merge.
  • GitLab displays a comment like: “Set by [MY NAME] to be merged automatically when the pipeline succeeds”.
  • However, if I refresh the page shortly after, I can see the merge has already happened, even though the MR pipeline had not finished.

So it appears that GitLab is merging prematurely, without waiting for the MR pipeline to complete.

Additional context:

The MR pipeline is defined in Jenkins with the following structure (more or less):
stages {
stage(‘Checkout Git CICD’) {
gitlabCommitStatus(name: ‘Checkout Git CICD’) {
// logic
}
}
stage(‘Build’) {
gitlabCommitStatus(name: ‘Build’) {
// logic
}
}
stage(‘Tests’) {
gitlabCommitStatus(name: ‘Tests’) {
// logic
}
}
}

post {
success {
updateGitlabCommitStatus name: ‘jenkins’, state: ‘success’
}
failure {
updateGitlabCommitStatus name: ‘jenkins’, state: ‘failed’
}
}

post {
success {
updateGitlabCommitStatus name: ‘jenkins’, state: ‘success’
}
failure {
updateGitlabCommitStatus name: ‘jenkins’, state: ‘failed’
}
}

Versions used:

  • GitLab Community Edition: v17.7.3
  • Jenkins GitLab Plugin: 1.9.8

Question:

Why is the auto-merge being executed before the MR pipeline has fully completed?
Is this a bug, or is there a misconfiguration in how GitLab interprets the Jenkins status updates?

Since the stages were not being detected correctly, we solved it in a different way.

At the beginning of the pipeline, we added a condition: updateGitlabCommitStatus name: 'Pipeline', state: 'pending', and at the end of the pipeline, depending on the outcome, we set either updateGitlabCommitStatus name: 'Pipeline', state: 'success' for success or updateGitlabCommitStatus name: 'Pipeline', state: 'failed' for failure. This way, GitLab won’t consider the pipeline as finished until this status is explicitly closed.