forked from cloudogu/ces-build-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
73 lines (58 loc) · 2.38 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!groovy
node('docker') {
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()
])
def cesBuildLib = libraryFromLocalRepo().com.cloudogu.ces.cesbuildlib
def mvn = cesBuildLib.MavenInDocker.new(this, "3.6.3-jdk-11")
mvn.useLocalRepoFromJenkins = true
def git = cesBuildLib.Git.new(this)
if ("master".equals(env.BRANCH_NAME)) {
mvn.additionalArgs = "-DperformRelease"
currentBuild.description = mvn.getVersion()
}
String emailRecipients = env.EMAIL_RECIPIENTS
catchError {
stage('Checkout') {
checkout scm
/* Don't remove folders starting in "." like
* .m2 (maven)
* .npm
* .cache, .local (bower)
*/
git.clean('".*/"')
}
stage('Build') {
// Run the maven build
mvn 'clean install -DskipTests'
archive 'target/*.jar'
}
stage('Unit Test') {
mvn 'test -Dmaven.test.failure.ignore=true'
// Archive Unit and integration test results, if any
junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml,**/target/surefire-reports/TEST-*.xml'
}
stage('SonarQube') {
generateCoverageReportForSonarQube(mvn)
def sonarQube = cesBuildLib.SonarQube.new(this, 'ces-sonar')
sonarQube.updateAnalysisResultOfPullRequestsToGitHub('sonarqube-gh-token')
sonarQube.analyzeWith(mvn)
if (!sonarQube.waitForQualityGateWebhookToBeCalled()) {
unstable("Pipeline unstable due to SonarQube quality gate failure")
}
}
}
mailIfStatusChanged(findEmailRecipients(emailRecipients))
}
static void generateCoverageReportForSonarQube(def mvn) {
mvn 'org.jacoco:jacoco-maven-plugin:0.8.5:report'
}
def libraryFromLocalRepo() {
// Workaround for loading the current repo as shared build lib.
// Checks out to workspace local folder named like the identifier.
// We have to pass an identifier with version (which is ignored). Otherwise the build fails.
library(identifier: 'ces-build-lib@snapshot', retriever: legacySCM(scm))
}