![](/img/trans.png)
[英]How to stop a jenkins pipeline build when tests fail - and mark it unstable
[英]How to mark build as failed if JS tests fail and mark build as UNSTABLE
我有一个运行单元测试的管道,当其中一个单元测试失败时,它将构建标记为不稳定,但是我需要使该构建失败并使其变为红色。
这是我的管道的示例
def gitStatus(buildStatus) {
if (buildStatus == 'SUCCESS') {
updateGitlabCommitStatus(name: 'build', state: 'success')
addGitLabMRComment comment: 'Build Passed'
}
updateGitlabCommitStatus(name: 'build', state: 'failed')
addGitLabMRComment comment: "Something unexpected happened. Inspect Jenkins logs."
emailext subject: '$DEFAULT_SUBJECT', body: '$DEFAULT_CONTENT', to: ''
}
try {
node ('Builder_1') {
stage('Preparing source tree') {
}
stage('Install Dependencies') {
sh '''#!/bin/bash
npm install --prefer-offline
'''
}
try {
stage ('Run Tests') {
withEnv(["JEST_JUNIT_OUTPUT=./jest-test-results.xml"]) {
sh 'npm run test -- --ci --testResultsProcessor="jest-junit"'
}
junit 'jest-test-results.xml'
}
} catch(err) {
step([$class: 'JUnitResultArchiver', testResults: './jest-test-results.xml'])
throw err
}
stage('Build') {
sh '''#!/bin/bash
npm run build
'''
}
}
}catch (e) {
if (currentBuild.result != 'SUCCESS'){
currentBuild.result == 'FAILURE'
}
throw err
} finally {
gitStatus(currentBuild.currentResult)
}
您能否提出您的想法,出什么问题了。
如果您使用error err
或sh "exit 1"
,而不是throw err
。 它将标记为红色。 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.