I’d like to ask about surfacing more detailed quality gate failure information in Azure DevOps logs when running Python scans via pysonar.
Current setup
-
SonarQube: self-hosted
-
Language: Python
-
CI: Azure DevOps
-
Scanner: pysonar
-
I’m running the scan from a bash script like this:
#!/bin/bash
# 1. Activate the environment where pysonar is installed
source ~/sonarqube/sonar-venv/bin/activate
echo "🔍 Running SonarQube Scan..."
SONAR_HOST="http://127.0.0.1:9000"
SONAR_TOKEN="***masked***" # stored as a pipeline secret
PROJECT_KEY="Automations_automationfunc_1d75a13d-59c4-4898-b29a-977900ff5189"
# 2. Run pysonar scan and wait on the quality gate
pysonar \
--sonar-host-url="$SONAR_HOST" \
--sonar-token="$SONAR_TOKEN" \
--sonar-project-key="$PROJECT_KEY" \
--sonar-sources=. \
--sonar-qualitygate-wait
SCAN_STATUS=$?
if [ $SCAN_STATUS -ne 0 ]; then
echo "❌ SonarQube scan failed, aborting commit. Status: $SCAN_STATUS"
exit 1
fi
# 3. Deactivate the environment after the job is done
deactivate
This works: when the quality gate fails, the script exits non-zero and my pipeline fails.
What I’m trying to achieve
What I can’t see right now in the Azure DevOps logs is:
-
Which condition(s) caused the quality gate to fail (e.g. “Coverage on new code < 80%”, “New bugs > 0”), and/or
-
A brief list/summary of the issues that triggered the failure
My goal is to print some useful information to the terminal / Azure DevOps pipeline logs at the moment the quality gate fails, so developers don’t always have to click through to SonarQube just to see why it failed.