From 5697c850f3581f5c833cd78c56169358ee00b52f Mon Sep 17 00:00:00 2001 From: Johannes Schnatterer Date: Wed, 11 Jul 2018 18:23:49 +0200 Subject: [PATCH] Jenkins: Updates SonarQube analysis props for SonarCloud and BitBucket. --- Jenkinsfile | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f566478a63..ae4b0767cf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ #!groovy -@Library('github.com/cloudogu/ces-build-lib@ac17d45') +@Library('github.com/cloudogu/ces-build-lib@9aadeeb') import com.cloudogu.ces.cesbuildlib.* node() { // No specific label @@ -19,13 +19,16 @@ node() { // No specific label // Maven build specified it must be 1.8.0-101 or newer def javaHome = tool 'JDK-1.8.0-101+' - withEnv(["JAVA_HOME=${javaHome}", "PATH=${env.JAVA_HOME}/bin:${env.PATH}"]) { + withEnv(["JAVA_HOME=${javaHome}", "PATH=${env.JAVA_HOME}/bin:${env.PATH}", + // Give Maven enough memory to do SonarQube analysis + "MAVEN_OPTS=-Xmx1g"]) { stage('Checkout') { checkout scm } stage('Build') { + // TODO release build only on default? or 2.0.0-M3 -> JavaDoc takes ages mvn 'clean install -DskipTests -DperformRelease -Dmaven.javadoc.failOnError=false' } @@ -34,9 +37,15 @@ node() { // No specific label } stage('SonarQube') { - def sonarQube = new SonarQube(this, 'ces-sonar') - sonarQube.analyzeWith(mvn) + def sonarQube = new SonarQube(this, 'sonarcloud.io') + + // TODO move this to ces-build-lib so we can use "sonarqube.analyzeWith(mvn)" here + analyzeWith(mvn) + + if (!sonarQube.waitForQualityGateWebhookToBeCalled()) { + currentBuild.result = 'UNSTABLE' + } } } } @@ -49,3 +58,30 @@ node() { // No specific label mailIfStatusChanged(defaultEmailRecipients) } + +void analyzeWith(Maven mvn) { + + withSonarQubeEnv('sonarcloud.io') { + + String mvnArgs = "${env.SONAR_MAVEN_GOAL} " + + "-Dsonar.host.url=${env.SONAR_HOST_URL} " + + "-Dsonar.login=${env.SONAR_AUTH_TOKEN} " + + if (isPullRequest()) { + echo "Analysing SQ in PR mode" + mvnArgs += "-Dsonar.pullrequest.base=${env.CHANGE_TARGET} " + + "-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} " + + "-Dsonar.pullrequest.key=${env.CHANGE_ID} " + + "-Dsonar.pullrequest.provider=bitbucketcloud " + + "-Dsonar.pullrequest.bitbucketcloud.owner=sdorra " + + "-Dsonar.pullrequest.bitbucketcloud.repository=sonarcloudtest " + } else { + mvnArgs += " -Dsonar.branch.name=${env.BRANCH_NAME} " + if (!"default".equals(env.BRANCH_NAME)) { + // Avoid exception "The main branch must not have a target" on master branch + mvnArgs += " -Dsonar.branch.target=default " + } + } + mvn "${mvnArgs}" + } +}