From 860a9bb49f5bedca8eac26246f7e753c964d01bd Mon Sep 17 00:00:00 2001 From: Jakub Rusz Date: Wed, 2 Feb 2022 16:49:18 +0100 Subject: [PATCH] tests/ci: fix sonarqube analysis for main branch Only use the branch options if it's actually running in a branch and analyse main without them, sonarqube otherwise doesn't recognize the main branch. --- schutzbot/sonarqube.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/schutzbot/sonarqube.sh b/schutzbot/sonarqube.sh index ca2e7022..e3f01e1e 100755 --- a/schutzbot/sonarqube.sh +++ b/schutzbot/sonarqube.sh @@ -10,14 +10,15 @@ curl "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scan unzip -q sonar-scanner-cli.zip SONAR_SCANNER_CMD="sonar-scanner-$SONAR_SCANNER_CLI_VERSION-linux/bin/sonar-scanner" +SCANNER_OPTS="-Dsonar.projectKey=osbuild:osbuild -Dsonar.sources=. -Dsonar.host.url=https://sonarqube.corp.redhat.com -Dsonar.login=$SONAR_SCANNER_TOKEN" -$SONAR_SCANNER_CMD -Dsonar.projectKey=osbuild:osbuild \ - -Dsonar.sources=. \ - -Dsonar.host.url=https://sonarqube.corp.redhat.com \ - -Dsonar.login="$SONAR_SCANNER_TOKEN" \ - -Dsonar.pullrequest.branch="$CI_COMMIT_BRANCH" \ - -Dsonar.pullrequest.key="$CI_COMMIT_SHA" \ - -Dsonar.pullrequest.base="main" +# add options for branch analysis if not running on main +if [ "$CI_COMMIT_BRANCH" != "main" ];then + SCANNER_OPTS="$SCANNER_OPTS -Dsonar.pullrequest.branch=$CI_COMMIT_BRANCH -Dsonar.pullrequest.key=$CI_COMMIT_SHA -Dsonar.pullrequest.base=main" +fi + +# run the sonar-scanner +eval "$SONAR_SCANNER_CMD $SCANNER_OPTS" SONARQUBE_URL="https://sonarqube.corp.redhat.com/dashboard?id=osbuild%3Aosbuild&pullRequest=$CI_COMMIT_SHA" # Report back to GitHub