gitlab-plugin icon indicating copy to clipboard operation
gitlab-plugin copied to clipboard

Gitlab still shows pipeline status as running even after success/failure is sent.

Open rahul799 opened this issue 4 years ago • 8 comments

I have made a declarative pipeline as follow

pipeline {
    agent any
    stages {
        stage('Code Quality') {
            steps {
                sh 'npm i'
                updateGitlabCommitStatus name: 'Code Quality Test Started', state: 'running'
                script{
                    try{
                        sh 'npm run lint'
                        updateGitlabCommitStatus name: 'Code Quality Test Succedded', state: 'success'
                    } catch (e) {
                        updateGitlabCommitStatus name: 'Code Quality Test failed', state: 'failed'
                    }
                }
            }
        }
        stage('Test') {
            steps {
                
                updateGitlabCommitStatus name: 'Code Test Started', state: 'running'
                script{
                    try{
                        sh 'npm run test'
                        updateGitlabCommitStatus name: 'Code Test Succedded', state: 'success'
                    } catch (e) {
                        updateGitlabCommitStatus name: 'Code Test failed', state: 'failed'
                        currentBuild.result = 'FAILURE'
                        error("Error")
                    }
                }
            }
        }
        stage('Build') {
            steps {
                updateGitlabCommitStatus name: 'Build started', state: 'pending'
                script{
                    try{
                        sh 'npm run build'
                        updateGitlabCommitStatus name: 'Build Succedded', state: 'success'
                    } catch (e) {
                        updateGitlabCommitStatus name: 'Build failed', state: 'failed'
                    }
                }
            }
        }
    }
}

Now even after the final status ( success/failure) is sent, I still get my pipeline status as running in gitlab as shown below. Screenshot 2021-07-15 at 2 02 04 AM. Please help.

rahul799 avatar Jul 14 '21 20:07 rahul799

Hi @rahul799

I think your Jenkinsfile is bad written. When you choose the "name" of the updateGitlabCommitStatus function. It should be the name of the stage. You change the name for each status. So the plugin send to Gitlab a different name and create new job. We can see it in the image. Gitlab see some jobs with Pending status. So the merged status is Pending.

pipeline {
    agent any
    stages {
        stage('Code Quality') {
            steps {
                sh 'npm i'
                updateGitlabCommitStatus name: 'Code Quality', state: 'running'
                script{
                    try{
                        sh 'npm run lint'
                        updateGitlabCommitStatus name: 'Code Quality', state: 'success'
                    } catch (e) {
                        updateGitlabCommitStatus name: 'Code Quality', state: 'failed'
                    }
                }
            }
        }
        stage('Test') {
            steps {
                
                updateGitlabCommitStatus name: 'Test', state: 'running'
                script{
                    try{
                        sh 'npm run test'
                        updateGitlabCommitStatus name: 'Test', state: 'success'
                    } catch (e) {
                        updateGitlabCommitStatus name: 'Test', state: 'failed'
                        currentBuild.result = 'FAILURE'
                        error("Error")
                    }
                }
            }
        }
        stage('Build') {
            steps {
                updateGitlabCommitStatus name: 'Build', state: 'pending'
                script{
                    try{
                        sh 'npm run build'
                        updateGitlabCommitStatus name: 'Build', state: 'success'
                    } catch (e) {
                        updateGitlabCommitStatus name: 'Build', state: 'failed'
                    }
                }
            }
        }
    }
}

Turiok avatar Oct 13 '21 16:10 Turiok

We are seeing the same issue but in scripted pipeline where we use try and catch blocks. Inside the try blocks , we execute multiple stages and once all the stages executes succesfully, it updates the gitlab status. This is not working as gitlab build still shows as pending after the job is completed

updateGitlabCommitStatus name: 'jenkins-ci', state: 'pending' 
try {
  stage('A) { }
  stage('B') { }
  updateGitlabCommitStatus name: 'jenkins-ci', state: 'success'
}
catch(exec) {
    updateGitlabCommitStatus name: 'jenkins-ci', state: 'failed'
    throw exec
}

guruvamsichintala5 avatar Jan 20 '22 16:01 guruvamsichintala5

Hello! We are seeing the same issue, without using try/catch blocks and using the same name for the updateGitlabCommitStatus function:

First, we update the status to "pending": stages { stage('Launch parallel jobs') { steps { // Update Gitlab commit status to "Running" state // https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit updateGitlabCommitStatus name: "${env.JOB_NAME}", state: 'running' script { [...] } } } }

Then, we update the commit status again with the final result: post { always { script { [...] } } failure { updateGitlabCommitStatus name: "${env.JOB_NAME}", state: 'failed' script { [...] } } success { updateGitlabCommitStatus name: "${env.JOB_NAME}", state: 'success' script { [...] } } aborted { updateGitlabCommitStatus name: "${env.JOB_NAME}", state: 'canceled' script { [...] } } }

This is not working as gitlab build still shows as pending after the job is completed. If we skip the first updateGitlabCommitStatus call (running), the second one (success/failed/cancelled) works perfectly. Could you hel us? Thank you!

cherran avatar Feb 23 '23 17:02 cherran

Thanks @cherran for reporting this issue! Let us investigate the matter further and get back to you as soon as possible.

krisstern avatar Feb 23 '23 17:02 krisstern

@krisstern thank you!!

cherran avatar Feb 23 '23 22:02 cherran

Are there any updates regarding this issue? We are facing this issue in our pipelines as well.

ShayanBits avatar Sep 09 '23 23:09 ShayanBits

Same issue here. The logs indicate that updateGitlabCommitStatus is successfully executed but the pipeline status does not update occasionally, though it is not always reproducible.

alkshmir avatar Jan 10 '24 04:01 alkshmir

@alkshmir I understand you, I faced the same problem. From time to time, information about the pipeline status is not updated in GitLab. Tasks are stuck in the "pending" status.

fastz0om avatar Mar 28 '24 15:03 fastz0om