ci(jenkins): tolerate missing workspace in post actions

This commit is contained in:
jenkins 2026-05-19 15:57:50 -03:00
parent e3e8a046e4
commit ba84082a1e
3 changed files with 45 additions and 21 deletions

10
Jenkinsfile vendored
View File

@ -427,6 +427,7 @@ PY
post { post {
always { always {
script { script {
try {
if (fileExists('build/junit-unit.xml') || fileExists('build/junit-glue.xml')) { if (fileExists('build/junit-unit.xml') || fileExists('build/junit-glue.xml')) {
try { try {
junit allowEmptyResults: true, testResults: 'build/junit-*.xml' junit allowEmptyResults: true, testResults: 'build/junit-*.xml'
@ -434,8 +435,15 @@ PY
echo "junit step unavailable: ${err.class.simpleName}" echo "junit step unavailable: ${err.class.simpleName}"
} }
} }
}
archiveArtifacts artifacts: 'build/**', allowEmptyArchive: true, fingerprint: true archiveArtifacts artifacts: 'build/**', allowEmptyArchive: true, fingerprint: true
} catch (Throwable err) {
if (err.class.simpleName == 'MissingContextVariableException') {
echo 'workspace unavailable; skipping post-build artifact collection'
} else {
throw err
}
}
}
} }
} }
} }

View File

@ -380,7 +380,7 @@ PY
script { script {
env.FLUX_BRANCH = sh( env.FLUX_BRANCH = sh(
returnStdout: true, returnStdout: true,
script: "awk '/branch:/{print $2; exit}' clusters/atlas/flux-system/gotk-sync.yaml" script: "grep -m1 '^\\s*branch:' clusters/atlas/flux-system/gotk-sync.yaml | sed 's/^\\s*branch:\\s*//'"
).trim() ).trim()
if (!env.FLUX_BRANCH) { if (!env.FLUX_BRANCH) {
error('Flux branch not found in gotk-sync.yaml') error('Flux branch not found in gotk-sync.yaml')
@ -426,6 +426,7 @@ PY
post { post {
always { always {
script { script {
try {
if (fileExists('build/junit-unit.xml') || fileExists('build/junit-glue.xml')) { if (fileExists('build/junit-unit.xml') || fileExists('build/junit-glue.xml')) {
try { try {
junit allowEmptyResults: true, testResults: 'build/junit-*.xml' junit allowEmptyResults: true, testResults: 'build/junit-*.xml'
@ -433,8 +434,15 @@ PY
echo "junit step unavailable: ${err.class.simpleName}" echo "junit step unavailable: ${err.class.simpleName}"
} }
} }
}
archiveArtifacts artifacts: 'build/**', allowEmptyArchive: true, fingerprint: true archiveArtifacts artifacts: 'build/**', allowEmptyArchive: true, fingerprint: true
} catch (Throwable err) {
if (err.class.simpleName == 'MissingContextVariableException') {
echo 'workspace unavailable; skipping post-build artifact collection'
} else {
throw err
}
}
}
} }
} }
} }

View File

@ -412,6 +412,8 @@ EOF
script { script {
env.QUALITY_OUTCOME = currentBuild.currentResult == 'SUCCESS' ? 'ok' : 'failed' env.QUALITY_OUTCOME = currentBuild.currentResult == 'SUCCESS' ? 'ok' : 'failed'
} }
script {
try {
container('git') { container('git') {
sh ''' sh '''
set -euo pipefail set -euo pipefail
@ -553,12 +555,18 @@ METRICS
esac esac
''' '''
} }
script {
if (fileExists('build/junit-data-prepper.xml')) { if (fileExists('build/junit-data-prepper.xml')) {
echo 'JUnit XML generated and archived under build/; Jenkins junit step is not installed on this controller.' echo 'JUnit XML generated and archived under build/; Jenkins junit step is not installed on this controller.'
} }
}
archiveArtifacts artifacts: 'build/**', allowEmptyArchive: true, fingerprint: true archiveArtifacts artifacts: 'build/**', allowEmptyArchive: true, fingerprint: true
} catch (Throwable err) {
if (err.class.simpleName == 'MissingContextVariableException') {
echo 'workspace unavailable; skipping post-build metrics and artifact collection'
} else {
throw err
}
}
}
} }
} }
} }