From a228e063f1797aa8506680116ba5ae743e2e7036 Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Wed, 21 Jan 2026 03:47:08 -0300 Subject: [PATCH] ci: harden unit test step and junit post --- Jenkinsfile | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5ea7008..151a104 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -95,26 +95,26 @@ spec: stage('Unit tests') { steps { container('tester') { - sh ''' - set -euo pipefail - python -m pip install --no-cache-dir -r requirements.txt -r requirements-dev.txt - mkdir -p build - python -m ruff check ariadne --select C90,PLR - python -m slipcover \ - --json \ - --out "${COVERAGE_JSON}" \ - --source ariadne \ - --fail-under "${COVERAGE_MIN}" \ - -m pytest -ra -vv --durations=20 --junitxml "${JUNIT_XML}" - python - <<'PY' - import json - with open("build/coverage.json", "r", encoding="utf-8") as handle: - payload = json.load(handle) - summary = payload.get("summary") or {} - percent = summary.get("percent_covered") - print(f"Coverage summary: {percent:.2f}%" if percent is not None else "Coverage summary unavailable") - PY - ''' + sh(script: ''' +set -euo pipefail +python -m pip install --no-cache-dir -r requirements.txt -r requirements-dev.txt +mkdir -p build +python -m ruff check ariadne --select C90,PLR +python -m slipcover \ + --json \ + --out "${COVERAGE_JSON}" \ + --source ariadne \ + --fail-under "${COVERAGE_MIN}" \ + -m pytest -ra -vv --durations=20 --junitxml "${JUNIT_XML}" +python - <<'PY' +import json +with open("build/coverage.json", "r", encoding="utf-8") as handle: + payload = json.load(handle) +summary = payload.get("summary") or {} +percent = summary.get("percent_covered") +print(f"Coverage summary: {percent:.2f}%" if percent is not None else "Coverage summary unavailable") +PY +'''.stripIndent()) } } } @@ -204,7 +204,15 @@ spec: post { always { - junit allowEmptyResults: true, testResults: 'build/junit.xml' + script { + if (fileExists('build/junit.xml')) { + try { + junit allowEmptyResults: true, testResults: 'build/junit.xml' + } catch (Throwable err) { + echo "junit step unavailable: ${err.class.simpleName}" + } + } + } archiveArtifacts artifacts: 'build/junit.xml,build/coverage.json', allowEmptyArchive: true, fingerprint: true script { def props = fileExists('build.env') ? readProperties(file: 'build.env') : [:]