-
Notifications
You must be signed in to change notification settings - Fork 5
/
jenkins-pipeline
98 lines (89 loc) · 4.14 KB
/
jenkins-pipeline
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
/*
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
def verbose = params.VERBOSE ?: '0'
podTemplate(
nodeSelector: params.NODE_SELECTOR,
activeDeadlineSeconds: 3600, // 1h total build limit
idleMinutes: 1,
// Secret volume with maven settings.xml for deploy, see also sim-link in "build" stage.
volumes: [ secretVolume(secretName: "jenkins-nexus", mountPath: "/root/jenkins-nexus")],
workspaceVolume: dynamicPVC(requestsSize: "20Gi"),
containers: [
containerTemplate(name: 'jnlp',
image: 'jenkins/inbound-agent:4.13-2-alpine',
runAsUser: '0',
resourceRequestCpu: '1',
resourceLimitCpu: '1',
resourceRequestMemory: '1Gi',
resourceLimitMemory: '1Gi'),
containerTemplate(name: 'maven',
image: params.BUILDER_IMAGE ?: 'maven:3.8.5-openjdk-17',
runAsUser: '0',
ttyEnabled: true,
command: 'cat',
resourceRequestCpu: params.BUILDER_CPU ?: '4',
resourceLimitCpu: params.BUILDER_CPU ?: '4',
resourceRequestMemory: '8Gi',
resourceLimitMemory: '8Gi') // see also -Xmx flag lower
]
) {
node(POD_LABEL) {
try {
stage("checkout") {
git branch: params.BRANCH ?: 'master',
url: 'https://github.com/Evolveum/midpoint-overlay-example'
}
stage("build") {
container('maven') {
sh """#!/bin/bash -ex
# .m2 is mutable and short-term, we just sym-link the settings.xml there.
mkdir -p /root/.m2
ln -s ../jenkins-nexus/settings.xml /root/.m2/settings.xml
if [ "${verbose}" -ge 1 ]; then
env | sort
mvn --version
df -h
fi
mvn -B -ntp clean ${params.SKIP_DEPLOY ? 'install' : 'deploy -DdeployAtEnd=true'}
if [ "${verbose}" -ge 1 ]; then
df -h
fi
"""
// If we get here it's success, test results can change it to UNSTABLE.
currentBuild.result = 'SUCCESS'
// Collects results for all tests
// Using this step in each phase produces multiple graphs, but all have the same results from the last run.
step([$class: 'Publisher',
reportFilenamePattern: '**/testng-results.xml',
failureOnFailedTestConfig: true // TODO we don't want failure, but how can we make it unstable?
])
if (currentBuild.result == 'UNSTABLE' || currentBuild.result == 'FAILURE' || params.ARCHIVE_LOGS) {
sh "find . -wholename '*/target/test.log' -print0 | tar -czf test-logs.tgz --null -T -"
archiveArtifacts allowEmptyArchive: true, artifacts: "test-logs.tgz", followSymlinks: false
}
}
}
} catch (Exception e) {
currentBuild.result = 'FAILURE' // error below will not set result for mailer!
error 'Marking build as FAILURE because of: ' + e
} finally {
try {
step([$class: 'Mailer',
notifyEveryUnstableBuild: true,
recipients: env.DEFAULT_MAIL_RECIPIENT,
sendToIndividuals: false])
sh """#!/bin/bash -ex
if [ "${verbose}" -ge 1 ]; then
df -h
fi
"""
} catch (Exception e) {
println 'Could not send email: ' + e
}
}
}
}