jenkinsci / jenkinsci/gitlab-plugin
Skipped stages due to earlier failure keep 'pending' and cause the pipeline in 'running' status
- Dominant language
- Java
- Stars
- 1.4k
- Forks
- 615
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 10
Description
## Issue
Skipped stages due to earlier failure keep `pending` and the pipeline status remain in `running` status.
### Context
- **Gitlab plugin version**: 1.5.12
- **Gitlab version**: 9.0.2-ee
- **Jenkins version**: 2.138.2
- **Job type**: declarative pipeline.
### Logs & Traces
Jenkins logs:
```
Test Suites: 1 failed, 80 passed, 81 total
Tests: 1 failed, 460 passed, 461 total
Snapshots: 40 passed, 40 total
Time: 73.369s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! email-editor@3.0.5 test:report: `node ../../scripts/test.js --env=jsdom --config config/jest/config.ci.js --coverage`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the email-editor@3.0.5 test:report script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /var/lib/jenkins/.npm/_logs/2019-05-23T05_00_20_986Z-debug.log
lerna ERR! npm run test:report exited 1 in 'email-editor'
lerna ERR! npm run test:report exited 1 in 'email-editor'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! xxx@1.0.0 test: `lerna exec -- npm run test:report`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the xxx@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /var/lib/jenkins/.npm/_logs/2019-05-23T05_00_21_013Z-debug.log
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // gitlabCommitStatus
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
Stage 'Build' skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] deleteDir
[Pipeline] updateGitlabCommitStatus
[Pipeline] emailext
Not sending mail to unregistered user
Sending email to:
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
There are still pending GitLab builds. Please check your configuration
[Pipeline] // gitlabBuilds
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE
```
GitLab pipeline status:

### Problem description
Just trying to update each stages' status to gitlab, but found when there is early stage failed, all subsequent stage will keep in 'pending' status, and the whole pipeline status remains in `running`
**Jenkins File**
```groovy
def sourceBranch = env.gitlabBranch ?: params.gitlabBranch
pipeline {
agent any
environment {
projectName = ""
checkoutDir = ""
repoSSHURL = ""
mailTo = ""
}
parameters {
string(
name: "gitlabBranch",
defaultValue: "master",
description: "Branch to build"
)
}
options {
skipDefaultCheckout()
gitLabConnection("Gitlab")
gitlabBuilds(builds: ["Init", "Inspect", "Test", "Build"])
}
triggers {
gitlab(
triggerOnPush: false,
triggerOnMergeRequest: true,
skipWorkInProgressMergeRequest: true,
branchFilterType: "All",
secretToken: ""
)
}
stages {
stage("Checkout") {
steps {
script {
echo "Gitlab merge request triggered build"
sourceBranch = env.gitlabSourceBranch
currentBuild.displayName = env.gitlabSourceBranch
checkout ([
$class: "GitSCM",
branches: [[name: "origin/${env.gitlabSourceBranch}"]],
extensions: [
[$class: "RelativeTargetDirectory", relativeTargetDir: "${checkoutDir}"],
[$class: "LocalBranch"],
[$class: "PreBuildMerge", options: [
fastForwardMode: "FF",
mergeRemote: "origin",
mergeStrategy: "DEFAULT",
mergeTarget: env.gitlabTargetBranch
]]
],
userRemoteConfigs: [[url: "${repoSSHURL}"]]
])
}
}
}
stage("Init") {
steps {
gitlabCommitStatus("Init") {
dir(checkoutDir) {
sh "npm ci"
sh "npm run bootstrap"
sh "npm run setup"
}
}
}
}
stage("Inspect") {
steps {
gitlabCommitStatus("Inspect") {
dir(checkoutDir) {
sh "npm run inspect"
}
}
}
}
stage("Test") {
steps {
gitlabCommitStatus("Test") {
dir(checkoutDir) {
sh "npm run test"
}
}
}
}
stage("Build") {
steps {
gitlabCommitStatus("Build") {
dir(checkoutDir) {
sh "npm run build"
}
}
}
}
}
post {
failure {
emailext([
body: "${projectName} build failed, see: ${env.BUILD_URL}",
mimeType: "text/html",
replyTo: "",
recipientProviders: [[$class: "CulpritsRecipientProvider"]],
subject: "${projectName} build (${sourceBranch}) - Failure",
to: "${mailTo}"
])
}
always {
deleteDir()
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.