-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathjenkins-pipeline
113 lines (104 loc) · 4.6 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* 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: 600, // 10min total build limit
idleMinutes: 10,
// No need for secret volume, no mvn deploy done here.
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") {
retry(3) {
git branch: params.BRANCH ?: 'master',
url: 'https://github.com/Evolveum/connector-ldap.git'
}
}
stage("build") {
container('maven') {
withCredentials([
usernamePassword(credentialsId:"dependencyTrack", usernameVariable:"DTRACK_URL", passwordVariable: "DTRACK_TOKEN")
]) {
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 -P sbom,dependencytrack clean ${params.SKIP_DEPLOY ? 'install' : 'deploy -DdeployAtEnd=true'}
if [ "${verbose}" -ge 1 ]; then
df -h
fi
"""
}
}
}
stage("collect-test-results") {
container('maven') {
// If we get here it's success, test results can change it to UNSTABLE.
currentBuild.result = 'SUCCESS'
step([
$class: 'Publisher',
reportFilenamePattern: '**/testng-results.xml',
failureOnFailedTestConfig: true
])
if (currentBuild.result == 'UNSTABLE' || 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 {
if (verbose > '0') {
echo "Build: ${currentBuild}"
echo "Result: ${currentBuild.currentResult}"
}
try {
// Very basic mails, later we can use https://plugins.jenkins.io/email-ext/
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
}
}
}
}