diff --git a/Jenkinsfile b/Jenkinsfile index 64c881183a..f139f54906 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,47 +1,107 @@ #!groovy -@Library('github.com/cloudogu/ces-build-lib@ac17d45') + +// Keep the version in sync with the one used in pom.xml in order to get correct syntax completion. +@Library('github.com/cloudogu/ces-build-lib@9aadeeb') import com.cloudogu.ces.cesbuildlib.* node() { // No specific label - properties([ - // Keep only the last 10 build to preserve space - buildDiscarder(logRotator(numToKeepStr: '10')), - // Don't run concurrent builds for a branch, because they use the same workspace directory - disableConcurrentBuilds() - ]) + // Change this as when we go back to default - necessary for proper SonarQube analysis + mainBranch = "2.0.0-m3" - String defaultEmailRecipients = env.EMAIL_SCM_RECIPIENTS + properties([ + // Keep only the last 10 build to preserve space + buildDiscarder(logRotator(numToKeepStr: '10')), + ]) - catchError { + catchError { - Maven mvn = new MavenWrapper(this) + Maven mvn = setupMavenBuild() + // Maven build specified it must be 1.8.0-101 or newer + def javaHome = tool 'JDK-1.8.0-101+' - stage('Checkout') { - checkout scm - } - - stage('Build') { - mvn 'clean install -DskipTests -DperformRelease' - archive '**/target/*.jar,**/target/*.zip' - } - - stage('Unit Test') { - mvn 'test -Dsonia.scm.test.skip.hg=true' - } - - stage('SonarQube') { - def sonarQube = new SonarQube(this, 'ces-sonar') - - sonarQube.analyzeWith(mvn) + withEnv(["JAVA_HOME=${javaHome}", "PATH=${env.JAVA_HOME}/bin:${env.PATH}"]) { + + stage('Checkout') { + checkout scm + } + + stage('Build') { + mvn 'clean install -DskipTests' + } + + stage('Unit Test') { + mvn 'test -Dsonia.scm.test.skip.hg=true' + } + + stage('SonarQube') { + + def sonarQube = new SonarQube(this, 'sonarcloud.io') + + analyzeWith(mvn) + + if (!sonarQube.waitForQualityGateWebhookToBeCalled()) { + currentBuild.result = 'UNSTABLE' } + } } + } - // Archive Unit and integration test results, if any - junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml,**/target/surefire-reports/TEST-*.xml,**/target/jest-reports/TEST-*.xml' + // Archive Unit and integration test results, if any + junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml,**/target/surefire-reports/TEST-*.xml,**/target/jest-reports/TEST-*.xml' - // Find maven warnings and visualize in job - warnings consoleParsers: [[parserName: 'Maven']], canRunOnFailed: true + // Find maven warnings and visualize in job + warnings consoleParsers: [[parserName: 'Maven']], canRunOnFailed: true - mailIfStatusChanged(defaultEmailRecipients) + mailIfStatusChanged(commitAuthorEmail) +} + +String mainBranch + +Maven setupMavenBuild() { + Maven mvn = new MavenWrapper(this) + + if (mainBranch.equals(env.BRANCH_NAME)) { + // Release starts javadoc, which takes very long, so do only for certain branches + mvn.additionalArgs += ' -DperformRelease' + // JDK8 is more strict, we should fix this before the next release. Right now, this is just not the focus, yet. + mvn.additionalArgs += ' -Dmaven.javadoc.failOnError=false' + } + return mvn +} + +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=scm-manager " + } else { + mvnArgs += " -Dsonar.branch.name=${env.BRANCH_NAME} " + if (!mainBranch.equals(env.BRANCH_NAME)) { + // Avoid exception "The main branch must not have a target" on main branch + mvnArgs += " -Dsonar.branch.target=${mainBranch} " + } + } + mvn "${mvnArgs}" + } +} + +String getCommitAuthorComplete() { + new Sh(this).returnStdOut 'hg log --branch . --limit 1 --template "{author}"' +} + +String getCommitAuthorEmail() { + def matcher = getCommitAuthorComplete() =~ "<(.*?)>" + matcher ? matcher[0][1] : "" } diff --git a/pom.xml b/pom.xml index 2416371d48..8d3b3fb0b2 100644 --- a/pom.xml +++ b/pom.xml @@ -145,10 +145,31 @@ ${mokito.version} test + + + + com.github.cloudogu + ces-build-lib + + 9aadeeb + + true + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.1 + + + + @@ -254,7 +275,6 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9 true ${project.build.sourceEncoding} @@ -439,7 +459,6 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.8.1 org.jboss.apiviz.APIviz diff --git a/scm-core/pom.xml b/scm-core/pom.xml index ddd443afb4..a06eb544dc 100644 --- a/scm-core/pom.xml +++ b/scm-core/pom.xml @@ -159,7 +159,6 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9 true ${project.build.sourceEncoding} diff --git a/scm-webapp/pom.xml b/scm-webapp/pom.xml index 98c70ff82a..d02db4d203 100644 --- a/scm-webapp/pom.xml +++ b/scm-webapp/pom.xml @@ -566,7 +566,7 @@ e1 javascript:S3827 **.js - src/main/webapp/resources/extjs/**,src/main/webapp/resources/moment/**,src/main/webapp/resources/syntaxhighlighter/** + src/main/webapp**