Hi, I am trying to get the result of the analysis performed by sonar, to validate if there are critical errors and report them as failure.
So far the analysis is correct, but if sonar identifies that there are critical errors in the code I can’t fail the pipeline, and I need it to fail.
This mi pipeline
image: maven:3.3.9
definitions:
steps:
- step: &build-step
name: SonarQube analysis
script:
- pipe: sonarsource/sonarqube-scan:2.0.1
variables:
SONAR_HOST_URL: ${SONAR_HOST_URL}
SONAR_TOKEN: ${SONAR_TOKEN}
caches:
sonar: ~/.sonar
clone:
depth: full
pipelines:
branches:
'{master}':
- step: *build-step
- step:
name: Check SonarQube Analysis
script:
- if [ -f report-task.txt ]; then
ERROR_COUNT=$(grep -c 'CRITICAL\|ERROR' report-task.txt);
if [ $ERROR_COUNT -gt 0 ]; then
echo "Failing the pipeline due to critical errors in SonarQube analysis.";
exit 1;
fi
else
echo "report-task.txt file not found. Failing the pipeline.";
exit 1;
fi
resultado:
- SonarQube analysis (OK).
- Check SonarQube Analysis (fail).
`if [ -f report-task.txt ]; then ERROR_COUNT=$(grep -c 'CRITICAL\|ERROR' report-task.txt);
if [ $ERROR_COUNT -gt 0 ]; then
echo "Failing the pipeline due to critical errors in SonarQube analysis."; exit 1;
fi else echo "report-task.txt file not found. Failing the pipeline."; exit 1; fi`
`report-task.txt file not found. Failing the pipeline.`
I have checked everywhere in the sonar interface to see where I have to configure it, I understand that not all sonarqube versions generate it automatically.
I did this search “find / -name report-task.txt 2>/dev/null” on the server and it doesn’t find it, so I don’t know what is missing or where is the failure.
I need some guidance
Thanks