Skip to content

Instantly share code, notes, and snippets.

@avarne
Created September 28, 2021 04:54
Embed
What would you like to do?
GitLab CI pipeline to execute SonarQube Scan using maven and checking status using Sonar REST api
stages:
- codequality
sonar-check:
stage: codequality
tags:
- demo
script:
- echo "codequality started for project"
- export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el7_9.x86_64/ && export PATH=$JAVA_HOME/bin:$PATH
- mvn clean package sonar:sonar -Dproject.settings=sonar.properties -Dsonar.projectKey=$CI_PROJECT_NAME -Dsonar.projectName=acm-client-sdk -Dmaven.test.skip=true
- echo "codequality finised for project checking for qualitydate"
- sleep 10s
- result=$(curl http://sonarqube.com:9000/api/qualitygates/project_status?projectKey=$CI_PROJECT_NAME)
- echo $result | if [ $(python -c 'import sys, json; print json.load(sys.stdin)["projectStatus"]["status"]') == "ERROR" ]; then exit 1; else echo "Sonar quality gate passed"; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment