Skip to content

Instantly share code, notes, and snippets.

@darius-sas
Last active June 13, 2023 07:21
Show Gist options
  • Save darius-sas/09a1e57f62817da00bbd330f8251e1d9 to your computer and use it in GitHub Desktop.
Save darius-sas/09a1e57f62817da00bbd330f8251e1d9 to your computer and use it in GitHub Desktop.
Execute Sonarqube on a Git repo
#!/bin/bash
set -e
# For example, you can generate these with `git tag --sort=creatordate`
tags=(commit1 commit2 ...)
# Some projects wont compile otherwise
JAVA_8_HOME=/path/to/java8
# Sonarqube needs a recent version of java to run
JAVA_17_HOME=/path/to/java8
SONAR_PROJECT_KEY=my-project
SONAR_URL=http://localhost:9000
SONAR_PROJECT_NAME=my-project-name
SONAR_TOKEN=sqp_abcd
for tag in ${tags[@]}; do
echo "Analysing $tag"
git checkout -f $tag
sed -i 's/<source>.*/<source>1.8<\/source>/g' pom.xml
sed -i 's/<target>.*/<target>1.8<\/target>/g' pom.xml
rm -rf src/test/java/**
export JAVA_HOME=${JAVA_8_HOME}
mvn clean compile
export JAVA_HOME=${JAVA_17_HOME}
mvn sonar:sonar \
-Dsonar.projectKey=${SONAR_PROJECT_KEY} \
-Dsonar.projectName=${SONAR_PROJECT_NAME} \
-Dsonar.host.url=${SONAR_URL} \
-Dsonar.login=${SONAR_TOKEN}
mvn clean > /dev/null
echo "DONE"
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment