-
Notifications
You must be signed in to change notification settings - Fork 536
/
Jenkinsfile
197 lines (167 loc) · 5.59 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!groovy
@Library('jenkins-pipeline-library@nexus') import com.gentics.*
JobContext.set(this)
final def gitCommitTag = '[Jenkins | ' + env.JOB_BASE_NAME + ']';
def branchName = null
String version = null
String tagName = null
pipeline {
agent {
kubernetes {
label env.BUILD_TAG
defaultContainer 'build'
yaml ocpWorker("""
apiVersion: v1
kind: Pod
spec:
containers:
- name: build
image: """ + buildEnvironmentDockerImage("build/Dockerfile", null, "build") + """
imagePullPolicy: Always
command:
- cat
tty: true
resources:
requests:
cpu: '0'
memory: '0'
limits:
cpu: '0'
memory: '0'
- name: docker
- name: jnlp
- name: selenium
image: selenium/standalone-chrome:3.141.59
tty: true
ports:
- containerPort: 4444
name: selenium
protocol: TCP
resources:
requests:
cpu: '0'
memory: '0'
limits:
cpu: '0'
memory: '0'
imagePullSecrets:
- name: jenkins-docker-pull-secret
""")
}
}
parameters {
booleanParam(name: 'checkGitCommit', defaultValue: false, description: 'If set to true, the current git revision is compared with the git revision of the last successful build. If they are equal, the build is skipped and env.BUILD_SKIPPED is set to true')
booleanParam(name: 'unitTests', defaultValue: true, description: 'Whether to run the unit tests')
booleanParam(name: 'release', defaultValue: false, description: 'Whether to perform a release')
booleanParam(name: 'releaseWithNewChangesOnly', defaultValue: true, description: 'Release: Abort the build if there are no new changes')
booleanParam(name: 'deployTesting', defaultValue: false, description: 'Deploy the snapshot version (only valid, if not release)')
}
triggers {
githubPush()
}
options {
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword')])
timestamps()
timeout(time: 4, unit: 'HOURS')
ansiColor('xterm')
}
stages {
stage('Check git commit') {
when {
expression {
return Boolean.valueOf(params.checkGitCommit)
}
}
steps {
script {
if ( env.GIT_COMMIT == env.GIT_PREVIOUS_SUCCESSFUL_COMMIT ) {
echo "env.GIT_COMMIT (" + env.GIT_COMMIT + ") = env.GIT_PREVIOUS_SUCCESSFUL_COMMIT (" + env.GIT_PREVIOUS_SUCCESSFUL_COMMIT + "). Skip building."
env.BUILD_SKIPPED = "true"
} else {
echo "env.GIT_COMMIT (" + env.GIT_COMMIT + ") != env.GIT_PREVIOUS_SUCCESSFUL_COMMIT (" + env.GIT_PREVIOUS_SUCCESSFUL_COMMIT + "). Need to rebuild."
}
}
}
}
stage('Build, Deploy') {
when {
expression {
return env.BUILD_SKIPPED != "true"
}
}
steps {
githubBuildStarted()
script {
branchName = GitHelper.fetchCurrentBranchName()
if (!version && Boolean.valueOf(params.release)) {
version = MavenHelper.getVersion()
}
if (version) {
version = MavenHelper.transformSnapshotToReleaseVersion(version)
MavenHelper.setVersion(version)
}
currentBuild.description = version
if (Boolean.valueOf(params.release)) {
// Release
echo "Invoking release build on branch " + branchName + ".."
currentBuild.description += ' - Release'
if (Boolean.valueOf(params.releaseWithNewChangesOnly)) {
def lastCommitMessage = GitHelper.getLastCommitMessage().trim()
if (lastCommitMessage.startsWith(gitCommitTag)) {
error "Aborting the release build because there are no new changes. Last commit message is: \"" + lastCommitMessage + "\""
}
}
sh 'mvn -B -U clean deploy' + (Boolean.valueOf(params.unitTests) ? '' : ' -DskipTests')
// Add the modified pom.xml and the generated changelog file
def releaseMessage = 'Release of version ' + version
GitHelper.addCommit('.', gitCommitTag + ' ' + releaseMessage)
tagName = version
GitHelper.addTag(tagName, releaseMessage)
} else if (Boolean.valueOf(params.deployTesting)) {
// deploy the (snapshot) artifacts, but not the changelog
sh 'mvn -B -U clean deploy -Dchangelog.phase=never ' + (Boolean.valueOf(params.unitTests) ? '' : ' -DskipTests')
} else {
sh 'mvn -B -U clean package' + (Boolean.valueOf(params.unitTests) ? '' : ' -DskipTests')
}
}
}
post {
always {
script {
if (Boolean.valueOf(params.unitTests)) {
junit "**/target/surefire-reports/*.xml"
}
}
}
}
}
stage("Publish release") {
when {
expression {
return Boolean.valueOf(params.release) && env.BUILD_SKIPPED != "true"
}
}
steps {
echo "Please move the contents of the Artifactory repository 'lan.releases.staging.alohaeditor' to 'lan.releases' now or the next step will fail"
input message: 'Publish the release now?', ok: 'Yes, I have moved the Artifactory files, publish the release now'
script {
def newVersion = MavenHelper.getNextSnapShotVersion(version)
MavenHelper.setVersion(newVersion)
GitHelper.addCommit('.', gitCommitTag + ' Prepare for the next development iteration (' + newVersion + ')')
sshagent(["git"]) {
GitHelper.pushBranch(branchName)
GitHelper.pushTag(tagName)
}
}
build job: 'alohaeditor-uploadrelease', parameters: [[$class: 'MavenMetadataParameterValue', artifactId: '',
artifactUrl: '', classifier: '', description: '', groupId: '', name: 'ALOHAEDITOR', packaging: '', version: version]]
}
}
}
post {
always {
githubBuildEnded()
notifyMattermostUsers()
}
}
}