Skip to content

Commit 2658b9f

Browse files
aksOpsclaude
andcommitted
ci(sonar): treat exit-1 (issues found) as scan success, not job failure
The CLI's three-state exit codes are part of its contract: 0=clean, 1=issues found (normal), 2+=tool error. GitHub Actions' default 'bash -e' shell propagated exit 1 from a healthy scan as a step failure — masking the 'job ran but found things' signal we actually want, and breaking the workflow on the very first run that found any issue. Fix: capture rc with set+e/set-e, fail the step only on rc>=2 (real tool error). The Quality gate step (still informational) keeps the 'should we block on the findings themselves?' decision, decoupled from 'did the scanner run?'. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 6d202ba commit 2658b9f

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

.github/workflows/sonar.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,30 @@ jobs:
7373
# XMLs are passed in as coverage evidence — one per Java module that
7474
# produces coverage. agent-scan writes JSON to .sonar-predictor/scan.json
7575
# and prints a human summary on stdout; we want both.
76+
#
77+
# IMPORTANT: the CLI uses three-state exit codes
78+
# 0 = clean (no findings at the floor)
79+
# 1 = issues found (a normal scan outcome, not a failure)
80+
# 2 = tool error (broken input, daemon unreachable, no Java)
81+
# Step success means "the scanner ran". Whether the *result* should
82+
# fail the build is decided by the Quality gate step below. We must
83+
# not let `bash -e` propagate exit-1 from a healthy scan as a job
84+
# failure; we propagate exit code only when it's >= 2.
7685
- name: Run self-scan
7786
run: |
87+
set +e
7888
export SONAR_PREDICTOR_HOME="$(pwd)/dist/target/skill/sonar-predictor"
7989
./plugin/skills/sonar-predictor/bin/sonar agent-scan analyze . \
8090
--coverage protocol/target/site/jacoco/jacoco.xml \
8191
--coverage daemon/target/site/jacoco/jacoco.xml \
8292
--coverage cli/target/site/jacoco/jacoco.xml
93+
rc=$?
94+
set -e
95+
echo "Self-scan exit code: $rc (0=clean, 1=issues found, 2+=tool error)"
96+
if [ "$rc" -ge 2 ]; then
97+
echo "::error::Self-scan tool error (exit $rc) — see step log."
98+
exit "$rc"
99+
fi
83100
84101
# Render headline counts into the GitHub job summary so reviewers see
85102
# the scan result inline on the run page without downloading artifacts.

0 commit comments

Comments
 (0)