-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjenkins-default-pipeline.groovy
More file actions
165 lines (146 loc) · 7.08 KB
/
jenkins-default-pipeline.groovy
File metadata and controls
165 lines (146 loc) · 7.08 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
def verbose = params.VERBOSE ?: false
def cleanGradleRepository = params.CLEAN_GRADLE_REPOSITORY ?: false
def gitRefType = params.GIT_REF_TYPE ?: "branch"
def gitRef = params.GIT_REF ?: "master"
def publish = params.PUBLISH ?: false
def publishChannel = params.PUBLISH_CHANNEL ?: ""
def buildNumber = env.BUILD_NUMBER ?: "0"
if (publish && publishChannel == "") {
if (gitRef == "master") {
publishChannel = "snapshot"
} else if (gitRef.startsWith("support-")) {
publishChannel = "support"
}
}
def gradleOptions = "-i -s " +
"-Dplugin.verifier.home.dir=/root/.pluginVerifier " +
"-Dorg.gradle.project.publishChannel=$publishChannel " +
"-Dorg.gradle.project.buildNumber=$buildNumber"
podTemplate(
activeDeadlineSeconds: 3600,
idleMinutes: 1,
// No need for secret volume, no mvn deploy done here.
workspaceVolume: dynamicPVC(requestsSize: "10Gi"),
volumes: [ persistentVolumeClaim(claimName: "midpoint-studio-gradle", mountPath: "/root/.gradle"),
persistentVolumeClaim(claimName: "midpoint-studio-plugin-verifier", mountPath: "/root/.pluginVerifier")],
containers: [
containerTemplate(name: 'jnlp',
image: 'jenkins/inbound-agent:4.13-2-alpine',
runAsUser: '0',
resourceRequestCpu: '1',
resourceLimitCpu: '1',
resourceRequestMemory: '1Gi',
resourceLimitMemory: '1Gi'),
containerTemplate(name: 'jdk',
image: "${params.BUILDER_IMAGE ?: 'maven:3.8.5-eclipse-temurin-17'}",
runAsUser: '0',
ttyEnabled: true,
command: 'cat',
resourceRequestCpu: "${params.BUILDER_CPU ?: '4'}",
resourceLimitCpu: "${params.BUILDER_CPU ?: '4'}",
resourceRequestMemory: '8Gi',
resourceLimitMemory: '8Gi')
]
) {
node(POD_LABEL) {
try {
timeout(time: 30, unit: 'MINUTES') {
lock("midpoint-studio-pvc-lock") {
stage("clean-gradle-repository") {
if (cleanGradleRepository) {
sh """#!/bin/bash -ex
rm -rf /root/.pluginVerifier/ides
ls -la /root/.gradle/
du -hs /root/.gradle/caches
rm -rf /root/.gradle/caches
"""
}
}
stage("checkout") {
def ref = gitRefType == "branch" ? gitRef : "refs/tags/${gitRef}"
checkout scmGit(
branches: [[name: "${ref}"]],
userRemoteConfigs: [[
url: 'https://github.com/Evolveum/midpoint-studio.git'
]]
)
}
stage("build") {
container('jdk') {
sh """#!/bin/bash -ex
if [ "${verbose}" = "true" ]
then
id
env | sort
./gradlew --version
fi
./gradlew --stop
./gradlew clean buildPlugin verifyPlugin $gradleOptions
"""
}
}
stage("publish") {
container('jdk') {
withCredentials([string(credentialsId: 'jetbrains-permanent-token', variable: 'PUBLISH_TOKEN')]) {
sh """#!/bin/bash -ex
if [ "${publish}" = "true" ]
then
./gradlew publishPlugin $gradleOptions
fi
"""
}
}
}
stage("post-build") {
archiveArtifacts artifacts: 'studio-idea-plugin/build/reports/pluginVerifier/**', followSymlinks: false
}
stage("cleanup") {
container('jdk') {
sh """#!/bin/bash -ex
du -hs /root/.gradle
./gradlew --stop
./gradlew cleanupGradleTransformCache
du -hs /root/.gradle
"""
}
sh """#!/bin/bash -ex
git clean -f -d
"""
sh """#!/bin/bash -ex
# Removes any jetbrains dep older than 30 days, mainly to remove old IDEA snapshots.
# Sometimes removes other stuff, but it should be refetched from remote repositories.
find /root/.gradle/caches/modules-2/files-2.1/com.jetbrains* -mindepth 2 -maxdepth 2 -mtime +30 -type d -exec rm -rf {} \\;
PLUGIN_VERIFIER_DIR=/root/.pluginVerifier/ides
if [ -d "\$PLUGIN_VERIFIER_DIR" ]; then
du -hs \$PLUGIN_VERIFIER_DIR/..
find \$PLUGIN_VERIFIER_DIR -mindepth 1 -maxdepth 1 -mtime +30 -type d -exec rm -rf {} \\;
fi
PLUGIN_CACHE_DIR=/root/.cache/pluginVerifier
if [ -d "\$PLUGIN_CACHE_DIR" ]; then
du -hs \$PLUGIN_CACHE_DIR
find \$PLUGIN_CACHE_DIR -mindepth 1 -maxdepth 2 -mtime +30 -type d -exec rm -rf {} \\\\;
fi
"""
}
}
}
} 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
}
}
}
}