Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(chore): sonarQube details #76

Merged
merged 4 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 8 additions & 32 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import groovy.json.JsonSlurper

/*
** Variables.
*/
properties([buildDiscarder(logRotator(numToKeepStr: '50'))])
def serie = '20.10'
def serie = '21.10'
def maintenanceBranch = "${serie}.x"
if (env.BRANCH_NAME.startsWith('release-')) {
env.BUILD = 'RELEASE'
Expand Down Expand Up @@ -79,37 +77,15 @@ try {

// sonarQube step to get qualityGate result
stage('Quality gate') {
node {
def reportFilePath = "target/sonar/report-task.txt"
def reportTaskFileExists = fileExists "${reportFilePath}"
if (reportTaskFileExists) {
echo "Found report task file"
def taskProps = readProperties file: "${reportFilePath}"
echo "taskId[${taskProps['ceTaskId']}]"
timeout(time: 10, unit: 'MINUTES') {
while (true) {
sleep 10
def taskStatusResult =
sh(returnStdout: true, script: "curl -s -X GET -u ${authString} \'${sonarProps['sonar.host.url']}/api/ce/task?id=${taskProps['ceTaskId']}\'")
echo "taskStatusResult[${taskStatusResult}]"
def taskStatus = new JsonSlurper().parseText(taskStatusResult).task.status
echo "taskStatus[${taskStatus}]"
// Status can be SUCCESS, ERROR, PENDING, or IN_PROGRESS. The last two indicate it's
// not done yet.
if (taskStatus != "IN_PROGRESS" && taskStatus != "PENDING") {
break;
}
def qualityGate = waitForQualityGate()
if (qualityGate.status != 'OK') {
currentBuild.result = 'FAIL'
}
}
}
}
if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
error("Quality gate failure: ${qualityGate.status}.");
timeout(time: 10, unit: 'MINUTES') {
def qualityGate = waitForQualityGate()
if (qualityGate.status != 'OK') {
currentBuild.result = 'FAIL'
}
}
if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
error("Quality gate failure: ${qualityGate.status}.");
}
}

stage('Package') {
Expand Down
16 changes: 16 additions & 0 deletions script/ci/analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,27 @@
set -e
set -x

# Project.
PROJECT=centreon-collect
PROJECT_NAME="Centreon Collect"

# Copy reports and run analysis.
cp ../broker.xml .
cp ../clib.xml .
cp ../engine.xml .

if [ -z "$VERSION" ]; then
VERSION="latest"
fi;

# environment values required to replace sonarQube project versioning and binding
# sonar.projectKey="{PROJECT_TITLE}"
# sonar.projectName="{PROJECT_NAME}"
# sonar.projectKey="{PROJECT_VERSION}"
sed -i -e "s/{PROJECT_TITLE}/$PROJECT/g" ../../sonar-project.properties
sed -i -e "s/{PROJECT_NAME}/$PROJECT_NAME/g" ../../sonar-project.properties
sed -i -e "s/{PROJECT_VERSION}/$VERSION/g" ../../sonar-project.properties

# override missing AMI requirement
sudo apt-get install shellcheck
sonar-scanner
7 changes: 4 additions & 3 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sonar.projectKey=centreon-collect
sonar.projectName=Centreon Collect
sonar.projectKey=20.10.0
# project
sonar.projectKey={PROJECT_TITLE}
sonar.projectName={PROJECT_NAME}
sonar.projectVersion={PROJECT_VERSION}
sonar.sources=.

sonar.tsql.file.suffixes=sql,tsql
Expand Down