Fix: Update CI workflow to improve SonarScanner installation process with enhanced error handling and version management
All checks were successful
CI / lint-and-test (pull_request) Successful in 57s
CI / ansible-validation (pull_request) Successful in 2m16s
CI / secret-scanning (pull_request) Successful in 53s
CI / dependency-scan (pull_request) Successful in 57s
CI / sast-scan (pull_request) Successful in 2m5s
CI / license-check (pull_request) Successful in 54s
CI / vault-check (pull_request) Successful in 1m53s
CI / playbook-test (pull_request) Successful in 2m20s
CI / container-scan (pull_request) Successful in 1m35s
CI / sonar-analysis (pull_request) Successful in 2m16s
CI / workflow-summary (pull_request) Successful in 51s

This commit is contained in:
ilia 2025-12-14 21:21:26 -05:00
parent 277a22d962
commit 699aaefac3

View File

@ -297,46 +297,79 @@ jobs:
set -e set -e
apt-get update && apt-get install -y wget curl unzip openjdk-17-jre apt-get update && apt-get install -y wget curl unzip openjdk-17-jre
# Download and install SonarScanner # Use a known working version to avoid download issues
echo "Detecting latest SonarScanner version..." SONAR_SCANNER_VERSION="5.0.1.3006"
SONAR_SCANNER_VERSION=$(curl -s https://api.github.com/repos/SonarSource/sonar-scanner-cli/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed 's/v//')
if [ -z "$SONAR_SCANNER_VERSION" ]; then
echo "Failed to detect version, using fallback version 5.0.1.3006"
SONAR_SCANNER_VERSION="5.0.1.3006"
fi
echo "Installing SonarScanner version: ${SONAR_SCANNER_VERSION}"
SCANNER_URL="https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip" SCANNER_URL="https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip"
echo "Installing SonarScanner version: ${SONAR_SCANNER_VERSION}"
echo "Downloading from: ${SCANNER_URL}" echo "Downloading from: ${SCANNER_URL}"
if ! wget -q --show-progress "${SCANNER_URL}" -O /tmp/sonar-scanner.zip; then
# Download with verbose error output
if ! wget --progress=bar:force "${SCANNER_URL}" -O /tmp/sonar-scanner.zip 2>&1; then
echo "❌ Failed to download SonarScanner" echo "❌ Failed to download SonarScanner"
echo "Checking if file was partially downloaded:"
ls -lh /tmp/sonar-scanner.zip 2>/dev/null || echo "No file found"
exit 1 exit 1
fi fi
# Verify download
if [ ! -f /tmp/sonar-scanner.zip ] || [ ! -s /tmp/sonar-scanner.zip ]; then
echo "❌ Downloaded file is missing or empty"
exit 1
fi
echo "Download complete. File size: $(du -h /tmp/sonar-scanner.zip | cut -f1)"
echo "Extracting SonarScanner..." echo "Extracting SonarScanner..."
if ! unzip -q /tmp/sonar-scanner.zip -d /tmp; then if ! unzip -q /tmp/sonar-scanner.zip -d /tmp; then
echo "❌ Failed to extract SonarScanner" echo "❌ Failed to extract SonarScanner"
echo "Archive info:"
file /tmp/sonar-scanner.zip || true
unzip -l /tmp/sonar-scanner.zip 2>&1 | head -20 || true
exit 1 exit 1
fi fi
# Find the extracted directory (handle both naming conventions)
EXTRACTED_DIR=""
if [ -d "/tmp/sonar-scanner-${SONAR_SCANNER_VERSION}-linux" ]; then if [ -d "/tmp/sonar-scanner-${SONAR_SCANNER_VERSION}-linux" ]; then
mv /tmp/sonar-scanner-${SONAR_SCANNER_VERSION}-linux /opt/sonar-scanner EXTRACTED_DIR="/tmp/sonar-scanner-${SONAR_SCANNER_VERSION}-linux"
elif [ -d "/tmp/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux" ]; then elif [ -d "/tmp/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux" ]; then
mv /tmp/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux /opt/sonar-scanner EXTRACTED_DIR="/tmp/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux"
else else
# Try to find any sonar-scanner directory
EXTRACTED_DIR=$(find /tmp -maxdepth 1 -type d -name "*sonar-scanner*" | head -1)
fi
if [ -z "$EXTRACTED_DIR" ] || [ ! -d "$EXTRACTED_DIR" ]; then
echo "❌ SonarScanner directory not found after extraction" echo "❌ SonarScanner directory not found after extraction"
ls -la /tmp/ | grep sonar echo "Contents of /tmp:"
ls -la /tmp/ | grep -E "(sonar|zip)" || ls -la /tmp/ | head -20
exit 1 exit 1
fi fi
ln -sf /opt/sonar-scanner/bin/sonar-scanner /usr/local/bin/sonar-scanner echo "Found extracted directory: ${EXTRACTED_DIR}"
chmod +x /opt/sonar-scanner/bin/sonar-scanner mv "${EXTRACTED_DIR}" /opt/sonar-scanner
chmod +x /usr/local/bin/sonar-scanner
# Create symlink
if [ -f /opt/sonar-scanner/bin/sonar-scanner ]; then
ln -sf /opt/sonar-scanner/bin/sonar-scanner /usr/local/bin/sonar-scanner
chmod +x /opt/sonar-scanner/bin/sonar-scanner
chmod +x /usr/local/bin/sonar-scanner
else
echo "❌ sonar-scanner binary not found in /opt/sonar-scanner/bin/"
echo "Contents of /opt/sonar-scanner/bin/:"
ls -la /opt/sonar-scanner/bin/ || true
exit 1
fi
echo "Verifying installation..." echo "Verifying installation..."
sonar-scanner --version || (echo "❌ SonarScanner verification failed" && exit 1) if ! sonar-scanner --version; then
echo "❌ SonarScanner verification failed"
echo "PATH: $PATH"
which sonar-scanner || echo "sonar-scanner not in PATH"
exit 1
fi
echo "✓ SonarScanner installed successfully"
- name: Verify SonarQube connection - name: Verify SonarQube connection
run: | run: |