From ba84082a1e68c5160ab89bc2cf4495005bed75fa Mon Sep 17 00:00:00 2001 From: jenkins Date: Tue, 19 May 2026 15:57:50 -0300 Subject: [PATCH] ci(jenkins): tolerate missing workspace in post actions --- Jenkinsfile | 20 +++++++++++++------ ci/Jenkinsfile.titan-iac | 22 ++++++++++++++------- services/logging/Jenkinsfile.data-prepper | 24 +++++++++++++++-------- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7420bf07..3c69062e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -427,15 +427,23 @@ PY post { always { script { - if (fileExists('build/junit-unit.xml') || fileExists('build/junit-glue.xml')) { - try { - junit allowEmptyResults: true, testResults: 'build/junit-*.xml' - } catch (Throwable err) { - echo "junit step unavailable: ${err.class.simpleName}" + try { + if (fileExists('build/junit-unit.xml') || fileExists('build/junit-glue.xml')) { + try { + junit allowEmptyResults: true, testResults: 'build/junit-*.xml' + } catch (Throwable err) { + echo "junit step unavailable: ${err.class.simpleName}" + } + } + 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 } } } - archiveArtifacts artifacts: 'build/**', allowEmptyArchive: true, fingerprint: true } } } diff --git a/ci/Jenkinsfile.titan-iac b/ci/Jenkinsfile.titan-iac index 85f9310c..89b8d93b 100644 --- a/ci/Jenkinsfile.titan-iac +++ b/ci/Jenkinsfile.titan-iac @@ -380,7 +380,7 @@ PY script { env.FLUX_BRANCH = sh( 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() if (!env.FLUX_BRANCH) { error('Flux branch not found in gotk-sync.yaml') @@ -426,15 +426,23 @@ PY post { always { script { - if (fileExists('build/junit-unit.xml') || fileExists('build/junit-glue.xml')) { - try { - junit allowEmptyResults: true, testResults: 'build/junit-*.xml' - } catch (Throwable err) { - echo "junit step unavailable: ${err.class.simpleName}" + try { + if (fileExists('build/junit-unit.xml') || fileExists('build/junit-glue.xml')) { + try { + junit allowEmptyResults: true, testResults: 'build/junit-*.xml' + } catch (Throwable err) { + echo "junit step unavailable: ${err.class.simpleName}" + } + } + 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 } } } - archiveArtifacts artifacts: 'build/**', allowEmptyArchive: true, fingerprint: true } } } diff --git a/services/logging/Jenkinsfile.data-prepper b/services/logging/Jenkinsfile.data-prepper index 919f9b9a..68fade7a 100644 --- a/services/logging/Jenkinsfile.data-prepper +++ b/services/logging/Jenkinsfile.data-prepper @@ -412,8 +412,10 @@ EOF script { env.QUALITY_OUTCOME = currentBuild.currentResult == 'SUCCESS' ? 'ok' : 'failed' } - container('git') { - sh ''' + script { + try { + container('git') { + sh ''' set -euo pipefail apk add --no-cache curl jq >/dev/null 2>&1 || true suite="${SUITE_NAME}" @@ -551,14 +553,20 @@ METRICS cat build/pushgateway-response.txt >&2 || true ;; esac - ''' - } - script { - if (fileExists('build/junit-data-prepper.xml')) { - echo 'JUnit XML generated and archived under build/; Jenkins junit step is not installed on this controller.' + ''' + } + if (fileExists('build/junit-data-prepper.xml')) { + echo 'JUnit XML generated and archived under build/; Jenkins junit step is not installed on this controller.' + } + 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 + } } } - archiveArtifacts artifacts: 'build/**', allowEmptyArchive: true, fingerprint: true } } }