我有一个管道,在管道开始时,在我们的github中,不同阶段的一堆状态被设置为pending。
在流水线的过程中,由于一些条件条件,这些阶段中的一些可能会被跳过。
我的阶段示例:
stage('Build') {
when {
allOf {
branch "PR-*"
expression { some expression... }
}
}
steps {
echo "GATE 2 - Build"
sh "some commands..."
}
post {
success {
script {
setStatus('build', 'success')
}
}
failure {
script {
setStatus('build', 'failure')
}
}
}
}
stage('Test') {
when {
allOf {
branch "PR-*"
expression { some expression... }
}
}
steps {
echo "GATE 2 - Test"
ansiColor('xterm') {
sh "some commands..."
}
}
post {
success {
setStatus('test', 'success')
}
failure {
setStatus('test', 'failure')
}
}
}setStatus
def call(String sectionName, String passOrFail) {
pullRequest.createStatus(
status: passOrFail,
context: 'continuous-integration/jenkins/pr-merge/' + sectionName,
description: sectionName + ' ' + passOrFail,
targetUrl: "${env.BUILD_URL}"
)
}然而,当stages确实被跳过时,当管道完成时,这将导致Github中针对拉取请求的状态检查处于挂起状态。
所以我的问题是,有没有一种方法可以神奇地删除状态检查,或者可能有一种方法可以检测哪些阶段被跳过,并对状态检查做些什么?
发布于 2021-10-24 21:21:42
您可以使用具有相同条件和表达式的not:
stages {
stage('Build') {
parallel {
stage('Build done') {
when {
expression {
buildConditions()
}
}
steps {
echo "GATE 2 - Build"
sh "echo 'Build commands...'"
}
post {
success {
script {
setStatus('build', 'success')
}
}
failure {
script {
setStatus('build', 'failure')
}
}
}
}
stage('Build skipped') {
when {
not {
expression {
buildConditions()
}
}
}
steps {
script {
setStatus('build', 'skipped')
}
}
}
}
}
/*
stage('Test') {
parallel {
stage('Test done') {
// ... as above ...
}
stage('Test skipped') {
// ... as above ...
}
}
}
*/
}
}
def buildConditions() {
return allOf {
expression { true }
expression { true }
}
}
def testConditions() {
return allOf {
expression { true }
expression { true }
}
}https://stackoverflow.com/questions/69679409
复制相似问题