@@ -39,15 +39,36 @@ jobs:
3939 **/target/failsafe-reports/**
4040 if-no-files-found : ignore
4141
42- - name : SonarQube Scan
42+ - name : SonarQube / SonarCloud Scan
4343 env :
4444 SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
4545 SONAR_HOST_URL : ${{ secrets.SONAR_HOST_URL }}
46+ SONAR_ORGANIZATION : ${{ secrets.SONAR_ORGANIZATION }}
47+ SONAR_PROJECT_KEY : ${{ secrets.SONAR_PROJECT_KEY }}
4648 run : |
4749 if [ -z "$SONAR_TOKEN" ] || [ -z "$SONAR_HOST_URL" ]; then
4850 echo "SONAR_* secrets chưa được cấu hình => bỏ qua phân tích Sonar."
4951 exit 0
5052 fi
51- mvn -B -DskipTests=true \
52- -Dsonar.coverage.jacoco.xmlReportPaths='**/target/site/**/jacoco*.xml' \
53- sonar:sonar
53+
54+ # Đường dẫn report JaCoCo aggregate (được tạo ở bước 'verify' của root pom)
55+ JACOCO_XML="target/site/jacoco-aggregate/jacoco.xml"
56+
57+ if echo "$SONAR_HOST_URL" | grep -qi "sonarcloud.io"; then
58+ # SonarCloud cần organization + projectKey
59+ if [ -z "$SONAR_ORGANIZATION" ] || [ -z "$SONAR_PROJECT_KEY" ]; then
60+ echo "Thiếu SONAR_ORGANIZATION hoặc SONAR_PROJECT_KEY cho SonarCloud."
61+ exit 1
62+ fi
63+ mvn -B -DskipTests=true \
64+ -Dsonar.organization="$SONAR_ORGANIZATION" \
65+ -Dsonar.projectKey="$SONAR_PROJECT_KEY" \
66+ -Dsonar.coverage.jacoco.xmlReportPaths="$JACOCO_XML" \
67+ sonar:sonar
68+ else
69+ # SonarQube self-hosted: KHÔNG dùng sonar.organization
70+ mvn -B -DskipTests=true \
71+ -Dsonar.coverage.jacoco.xmlReportPaths="$JACOCO_XML" \
72+ sonar:sonar
73+ fi
74+
0 commit comments