forked from cloudogu/command-bus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
98 lines (74 loc) · 2.49 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!groovy
@Library('github.com/cloudogu/ces-build-lib@6cff6d9d')
import com.cloudogu.ces.cesbuildlib.*
properties([
// Keep only the most recent builds in order to preserve space
buildDiscarder(logRotator(numToKeepStr: '20')),
// Don't run concurrent builds for a branch, because they use the same workspace directory
disableConcurrentBuilds()
])
node {
def javaHome = tool 'JDK8'
Maven mvn = new MavenWrapper(this, javaHome)
Git git = new Git(this)
catchError {
stage('Checkout') {
checkout scm
git.clean('')
}
initMaven(mvn)
stage('Build') {
mvn 'clean install -DskipTests'
archive '**/target/*.jar'
}
stage('Unit Test') {
mvn 'test'
}
stage('Integration Test') {
mvn 'verify -DskipUnitTests'
}
stage('Static Code Analysis') {
def sonarQube = new SonarCloud(this, [sonarQubeEnv: 'sonarcloud.io-cloudogu'])
sonarQube.analyzeWith(mvn)
if (!sonarQube.waitForQualityGateWebhookToBeCalled()) {
currentBuild.result ='UNSTABLE'
}
}
stage('Deploy') {
if (preconditionsForDeploymentFulfilled()) {
mvn.useDeploymentRepository([id: 'ossrh', url: 'https://oss.sonatype.org/',
credentialsId: 'mavenCentral-acccessToken', type: 'Nexus2'])
mvn.setSignatureCredentials('mavenCentral-secretKey-asc-file',
'mavenCentral-secretKey-Passphrase')
mvn.deployToNexusRepositoryWithStaging()
}
}
}
// Archive Unit and integration test results, if any
junit allowEmptyResults: true,
testResults: '**/target/surefire-reports/TEST-*.xml, **/target/failsafe-reports/*.xml'
// Find maven warnings and visualize in job
warnings consoleParsers: [[parserName: 'Maven']]
mailIfStatusChanged(git.commitAuthorEmail)
}
boolean preconditionsForDeploymentFulfilled() {
if (isBuildSuccessful() &&
!isPullRequest() &&
shouldBranchBeDeployed()) {
return true
} else {
echo "Skipping deployment because of branch or build result: currentResult=${currentBuild.currentResult}, " +
"result=${currentBuild.result}, branch=${env.BRANCH_NAME}."
return false
}
}
private boolean shouldBranchBeDeployed() {
return env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'develop'
}
void initMaven(Maven mvn) {
if ("master".equals(env.BRANCH_NAME)) {
echo "Building master branch"
mvn.additionalArgs = "-DperformRelease"
currentBuild.description = mvn.getVersion()
}
}