Gitlab still shows pipeline status as running even after success/failure is sent.
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.
.
Please help.
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'
}
}
}
}
}
}
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
}
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!
Thanks @cherran for reporting this issue! Let us investigate the matter further and get back to you as soon as possible.
@krisstern thank you!!
Are there any updates regarding this issue? We are facing this issue in our pipelines as well.
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 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.