2018-05-31 12:34:34 +02:00
|
|
|
#!groovy
|
2018-07-12 11:06:54 +02:00
|
|
|
|
|
|
|
|
// Keep the version in sync with the one used in pom.xml in order to get correct syntax completion.
|
2018-07-25 16:27:36 +02:00
|
|
|
@Library('github.com/cloudogu/ces-build-lib@59d3e94')
|
2018-05-31 12:34:34 +02:00
|
|
|
import com.cloudogu.ces.cesbuildlib.*
|
|
|
|
|
|
2018-09-24 13:04:03 +02:00
|
|
|
node('docker') {
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-07-12 11:46:50 +02:00
|
|
|
// Change this as when we go back to default - necessary for proper SonarQube analysis
|
|
|
|
|
mainBranch = "2.0.0-m3"
|
|
|
|
|
|
2018-07-11 18:07:26 +02:00
|
|
|
properties([
|
|
|
|
|
// Keep only the last 10 build to preserve space
|
2018-09-21 09:07:12 +02:00
|
|
|
buildDiscarder(logRotator(numToKeepStr: '10')),
|
|
|
|
|
disableConcurrentBuilds()
|
2018-07-11 18:07:26 +02:00
|
|
|
])
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-11-30 09:54:55 +01:00
|
|
|
timeout(activity: true, time: 30, unit: 'MINUTES') {
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
catchError {
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
Maven mvn = setupMavenBuild()
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
stage('Checkout') {
|
|
|
|
|
checkout scm
|
|
|
|
|
}
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
stage('Build') {
|
2019-01-28 14:28:34 +01:00
|
|
|
mvn 'clean install -Pdoc -DskipTests'
|
2018-09-12 18:01:00 +02:00
|
|
|
}
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
stage('Unit Test') {
|
|
|
|
|
mvn 'test -Dsonia.scm.test.skip.hg=true -Dmaven.test.failure.ignore=true'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stage('Integration Test') {
|
|
|
|
|
mvn 'verify -Pit -pl :scm-webapp,:scm-it -Dmaven.test.failure.ignore=true'
|
|
|
|
|
}
|
2018-08-06 16:37:22 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
stage('SonarQube') {
|
2018-07-11 18:07:26 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
analyzeWith(mvn)
|
2018-07-11 18:23:49 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
if (!waitForQualityGateWebhookToBeCalled()) {
|
|
|
|
|
currentBuild.result = 'UNSTABLE'
|
|
|
|
|
}
|
2018-07-11 18:07:26 +02:00
|
|
|
}
|
2018-09-24 13:03:02 +02:00
|
|
|
|
2018-09-24 17:13:47 +02:00
|
|
|
def commitHash = getCommitHash()
|
|
|
|
|
def dockerImageTag = "2.0.0-dev-${commitHash.substring(0,7)}-${BUILD_NUMBER}"
|
|
|
|
|
|
2018-09-25 09:22:25 +02:00
|
|
|
if (isMainBranch()) {
|
2019-01-30 11:25:01 +01:00
|
|
|
|
2019-02-21 13:32:27 +01:00
|
|
|
// stage('Lifecycle') {
|
|
|
|
|
// nexusPolicyEvaluation iqApplication: selectedApplication('scm'), iqScanPatterns: [[scanPattern: 'scm-server/target/scm-server-app.zip']], iqStage: 'build'
|
|
|
|
|
// }
|
2019-01-30 11:25:01 +01:00
|
|
|
|
2019-01-16 14:40:34 +01:00
|
|
|
stage('Archive') {
|
|
|
|
|
archiveArtifacts 'scm-webapp/target/scm-webapp.war'
|
|
|
|
|
archiveArtifacts 'scm-server/target/scm-server-app.*'
|
2019-01-28 14:28:34 +01:00
|
|
|
archiveArtifacts 'scm-webapp/target/scm-webapp-restdocs.zip'
|
2019-01-16 14:40:34 +01:00
|
|
|
}
|
|
|
|
|
|
2018-09-25 09:22:25 +02:00
|
|
|
stage('Docker') {
|
|
|
|
|
def image = docker.build('cloudogu/scm-manager')
|
|
|
|
|
docker.withRegistry('', 'hub.docker.com-cesmarvin') {
|
|
|
|
|
image.push(dockerImageTag)
|
|
|
|
|
image.push('latest')
|
|
|
|
|
}
|
2018-09-24 13:03:02 +02:00
|
|
|
}
|
2018-09-24 17:13:47 +02:00
|
|
|
|
2018-09-25 09:22:25 +02:00
|
|
|
stage('Deployment') {
|
|
|
|
|
build job: 'scm-manager/next-scm.cloudogu.com', propagate: false, wait: false, parameters: [
|
|
|
|
|
string(name: 'changeset', value: commitHash),
|
|
|
|
|
string(name: 'imageTag', value: dockerImageTag)
|
|
|
|
|
]
|
|
|
|
|
}
|
2018-09-24 17:13:47 +02:00
|
|
|
}
|
2018-05-31 12:34:34 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
// 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'
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
// Find maven warnings and visualize in job
|
|
|
|
|
warnings consoleParsers: [[parserName: 'Maven']], canRunOnFailed: true
|
2018-06-27 11:41:25 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
mailIfStatusChanged(commitAuthorEmail)
|
|
|
|
|
}
|
2018-05-31 12:34:34 +02:00
|
|
|
}
|
2018-07-11 18:23:49 +02:00
|
|
|
|
2018-07-12 11:46:50 +02:00
|
|
|
String mainBranch
|
2018-07-12 10:55:03 +02:00
|
|
|
|
2018-07-12 11:15:24 +02:00
|
|
|
Maven setupMavenBuild() {
|
2018-09-12 17:59:03 +02:00
|
|
|
// Keep this version number in sync with .mvn/maven-wrapper.properties
|
|
|
|
|
Maven mvn = new MavenInDocker(this, "3.5.2-jdk-8")
|
2018-07-12 11:15:24 +02:00
|
|
|
|
2018-09-25 09:22:25 +02:00
|
|
|
if (isMainBranch()) {
|
2018-07-12 11:15:24 +02:00
|
|
|
// 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
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-11 18:23:49 +02:00
|
|
|
void analyzeWith(Maven mvn) {
|
|
|
|
|
|
2018-09-07 10:29:58 +02:00
|
|
|
withSonarQubeEnv('sonarcloud.io-scm') {
|
2018-07-11 18:23:49 +02:00
|
|
|
|
|
|
|
|
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 " +
|
2018-12-04 15:52:02 +01:00
|
|
|
"-Dsonar.pullrequest.bitbucketcloud.repository=scm-manager " +
|
|
|
|
|
"-Dsonar.cpd.exclusions=**/*StoreFactory.java,**/*UserPassword.js "
|
2018-07-11 18:23:49 +02:00
|
|
|
} else {
|
|
|
|
|
mvnArgs += " -Dsonar.branch.name=${env.BRANCH_NAME} "
|
2018-09-25 09:22:25 +02:00
|
|
|
if (!isMainBranch()) {
|
2018-07-12 10:55:03 +02:00
|
|
|
// Avoid exception "The main branch must not have a target" on main branch
|
|
|
|
|
mvnArgs += " -Dsonar.branch.target=${mainBranch} "
|
2018-07-11 18:23:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mvn "${mvnArgs}"
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-12 10:32:24 +02:00
|
|
|
|
2018-09-25 09:22:25 +02:00
|
|
|
boolean isMainBranch() {
|
|
|
|
|
return mainBranch.equals(env.BRANCH_NAME)
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-16 11:38:04 +02:00
|
|
|
boolean waitForQualityGateWebhookToBeCalled() {
|
2018-07-16 11:54:35 +02:00
|
|
|
boolean isQualityGateSucceeded = true
|
2018-10-09 11:17:06 +02:00
|
|
|
timeout(time: 5, unit: 'MINUTES') { // Needed when there is no webhook for example
|
2018-07-16 11:38:04 +02:00
|
|
|
def qGate = waitForQualityGate()
|
|
|
|
|
echo "SonarQube Quality Gate status: ${qGate.status}"
|
|
|
|
|
if (qGate.status != 'OK') {
|
2018-07-16 11:54:35 +02:00
|
|
|
isQualityGateSucceeded = false
|
2018-07-16 11:38:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-07-16 11:54:35 +02:00
|
|
|
return isQualityGateSucceeded
|
2018-07-16 11:38:04 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-12 10:32:24 +02:00
|
|
|
String getCommitAuthorComplete() {
|
|
|
|
|
new Sh(this).returnStdOut 'hg log --branch . --limit 1 --template "{author}"'
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-24 17:13:47 +02:00
|
|
|
String getCommitHash() {
|
|
|
|
|
new Sh(this).returnStdOut 'hg log --branch . --limit 1 --template "{node}"'
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 10:32:24 +02:00
|
|
|
String getCommitAuthorEmail() {
|
|
|
|
|
def matcher = getCommitAuthorComplete() =~ "<(.*?)>"
|
|
|
|
|
matcher ? matcher[0][1] : ""
|
|
|
|
|
}
|