forked from gentics/mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
216 lines (198 loc) · 7.28 KB
/
Copy pathJenkinsfile
File metadata and controls
216 lines (198 loc) · 7.28 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// The GIT repository for this pipeline lib is defined in the global Jenkins setting
@Library('jenkins-pipeline-library')
import com.gentics.*
// Make the helpers aware of this jobs environment
JobContext.set(this)
properties([
parameters([
booleanParam(name: 'runTests', defaultValue: true, description: "Whether to run the unit tests"),
booleanParam(name: 'runPerformanceTests', defaultValue: false, description: "Whether to run performance tests."),
booleanParam(name: 'runClusterTests', defaultValue: false, description: "Whether to run cluster tests."),
booleanParam(name: 'runDeploy', defaultValue: false, description: "Whether to run the deploy steps."),
booleanParam(name: 'runDocker', defaultValue: false, description: "Whether to run the docker steps."),
booleanParam(name: 'runMavenBuild', defaultValue: false, description: "Whether to run the maven build steps."),
booleanParam(name: 'runIntegrationTests', defaultValue: false, description: "Whether to run integration tests.")
])
])
final def gitCommitTag = '[Jenkins | ' + env.JOB_BASE_NAME + ']';
node("docker") {
stage("Setup Build Environment") {
checkout scm
sh "cd .jenkins && docker build -t registry.gentics.com/jenkins-slave-mesh ."
sh "cd .jenkins && docker push registry.gentics.com/jenkins-slave-mesh"
podTemplate(containers: [
containerTemplate(alwaysPullImage: true, args: '${computer.jnlpmac} ${computer.name}',
command: '',
image: 'registry.gentics.com/jenkins-slave-mesh',
name: 'jnlp',
privileged: false,
ttyEnabled: true,
resourceRequestCpu: '2',
resourceRequestMemory: '1024Mi',
workingDir: '/home/jenkins/workspace'),
containerTemplate(alwaysPullImage: false,
command: '',
image: 'docker:dind',
name: 'dind',
privileged: true,
ttyEnabled: true,
resourceRequestCpu: '500m',
resourceRequestMemory: '1024Mi',
workingDir: '/root')
],
inheritFrom: '',
instanceCap: 10,
label: 'mesh',
name: 'jenkins-slave-mesh',
namespace: 'default',
serviceAccount: 'jenkins',
volumes: [
emptyDirVolume(memory: false, mountPath: '/var/run'),
persistentVolumeClaim(claimName: 'jenkins-maven-repository', mountPath: '/home/jenkins/.m2/repository', readOnly: false),
persistentVolumeClaim(claimName: 'jenkins-credentials', mountPath: '/home/jenkins/credentials', readOnly: true)
],
workspaceVolume: emptyDirWorkspaceVolume(false)) {
node("mesh") {
//env.DOCKER_HOST = "tcp://127.0.0.1:2375"
stage("Checkout") {
checkout scm
}
def branchName = GitHelper.fetchCurrentBranchName()
def version = MavenHelper.getVersion()
stage("Set Version") {
if (Boolean.valueOf(params.runDeploy)) {
if (version) {
echo "Building version " + version
version = MavenHelper.transformSnapshotToReleaseVersion(version)
MavenHelper.setVersion(version)
}
//TODO only add pom.xml files
sh 'git add .'
sh "git commit -m 'Raise version'"
GitHelper.addTag(version, 'Release of version ' + version)
}
}
stage("Test") {
if (Boolean.valueOf(params.runTests)) {
def splits = 20;
sh "ls -la"
sh "find -name \"*Test.java\" | grep -v Abstract | shuf | sed 's/.*java\\/\\(.*\\)/\\1/' > alltests"
sh "cat alltests | wc -l"
sh "split -a 2 -d -n l/${splits} alltests includes-"
stash includes: '**', name: 'project'
def branches = [:]
for (int i = 0; i < splits; i++) {
def current = i
branches["split${i}"] = {
node('mesh') {
echo "Preparing slave environment for ${current}"
unstash 'project'
def postfix = current;
if (current <= 9) {
postfix = "0" + current
}
echo "Setting correct inclusions file ${postfix}"
sh "mv includes-${postfix} inclusions.txt"
sshagent(["git"]) {
try {
sh "mvn -fae -Dmaven.javadoc.skip=true -Dmaven.test.failure.ignore=true -B -U -e -P inclusions -pl '!demo,!doc,!distributed,!performance-tests' clean package"
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml'])
}
}
}
}
}
try {
parallel branches
} catch (err) {
echo "Failed " + err.getMessage()
error err.getMessage()
}
} else {
echo "Tests skipped.."
}
}
stage("Maven Build") {
if (Boolean.valueOf(params.runMavenBuild)) {
sshagent(["git"]) {
if (Boolean.valueOf(params.runDeploy)) {
sh "mvn -U -B -DskipTests clean deploy"
} else {
sh "mvn -B -DskipTests clean package"
}
}
} else {
echo "Maven build skipped.."
}
}
stage("Cluster Tests") {
if (Boolean.valueOf(params.runClusterTests)) {
try {
sh "mvn -B -DskipTests clean install -pl '!demo,!doc'"
sh "mvn -B test -pl distributed"
} finally {
step([$class: 'JUnitResultArchiver', testResults: 'distributed/target/surefire-reports/*.xml'])
}
} else {
echo "Cluster tests skipped.."
}
}
stage("Docker Build") {
if (Boolean.valueOf(params.runDocker)) {
sh "rm demo/target/*sources.jar"
sh "rm server/target/*sources.jar"
sh "captain build"
} else {
echo "Docker build skipped.."
}
}
stage("Performance Tests") {
if (Boolean.valueOf(params.runPerformanceTests)) {
try {
sh "mvn -B -U clean package -pl '!doc,!demo,!distributed,!verticles,!server' -Dskip.unit.tests=true -Dskip.performance.tests=false -Dmaven.test.failure.ignore=true"
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/*.performance.xml'])
}
} else {
echo "Performance tests skipped.."
}
}
stage("Integration Tests") {
if (Boolean.valueOf(params.runIntegrationTests)) {
withEnv(["MESH_VERSION=" + version]) {
sh "integration-tests/test.sh"
}
} else {
echo "Performance tests skipped.."
}
}
stage("Deploy") {
if (Boolean.valueOf(params.runDeploy)) {
if (Boolean.valueOf(params.runDocker)) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'dockerhub_login', passwordVariable: 'DOCKER_HUB_PASSWORD', usernameVariable: 'DOCKER_HUB_USERNAME']]) {
sh 'docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD'
sh "captain push"
}
}
} else {
echo "Deploy skipped.."
}
}
stage("Git push") {
if (Boolean.valueOf(params.runDeploy)) {
sshagent(["git"]) {
def snapshotVersion = MavenHelper.getNextSnapShotVersion(version)
MavenHelper.setVersion(snapshotVersion)
GitHelper.addCommit('.', gitCommitTag + ' Prepare for the next development iteration (' + snapshotVersion + ')')
GitHelper.pushBranch(branchName)
GitHelper.pushTag(version)
}
} else {
echo "Push skipped.."
}
}
}
}
}
}