-
Notifications
You must be signed in to change notification settings - Fork 20
/
Jenkinsfile
222 lines (203 loc) · 8.08 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env groovy
def dirPrefix = 'ci-cscs-reframe-tests'
def loginBash = '#!/bin/bash -l'
def machinesList = params.machines.split()
def machinesToRun = machinesList
def runTests = true
def uniqueID
stage('Initialization') {
node('master') {
try {
uniqueID = "${env.ghprbActualCommit[0..6]}-${env.BUILD_ID}"
echo 'Environment Variables:'
echo sh(script: 'env|sort', returnStdout: true)
def githubComment = env.ghprbCommentBody
if (githubComment == 'null' || !githubComment.trim().startsWith('@jenkins-cscs')) {
machinesToRun = machinesList
currentBuild.result = 'SUCCESS'
return
}
def splittedComment = githubComment.split()
if (splittedComment.size() < 3) {
println 'No machines were found. Aborting...'
currentBuild.result = 'ABORTED'
return
}
if (splittedComment[1] != 'retry') {
println "Invalid command ${splittedComment[1]}. Aborting..."
currentBuild.result = 'ABORTED'
return
}
if (splittedComment[2] == 'all') {
machinesToRun = machinesList
currentBuild.result = 'SUCCESS'
return
}
else if (splittedComment[2] == 'none') {
runTests = false
currentBuild.result = 'SUCCESS'
return
}
machinesRequested = []
for (i = 2; i < splittedComment.size(); i++) {
machinesRequested.add(splittedComment[i])
}
machinesToRun = machinesRequested.findAll({it in machinesList})
if (!machinesToRun) {
println 'No machines were found. Aborting...'
currentBuild.result = 'ABORTED'
return
}
currentBuild.result = 'SUCCESS'
} catch(err) {
println err.toString()
if (err.toString().contains('exit code 143')) {
currentBuild.result = "ABORTED"
}
else if (err.toString().contains('Queue task was cancelled')) {
currentBuild.result = "ABORTED"
}
else {
currentBuild.result = "FAILURE"
}
}
}
}
if (!runTests) {
println "Won't execute any test (${currentBuild.result}). Exiting..."
return
}
if (currentBuild.result != 'SUCCESS') {
println "Initialization failed (${currentBuild.result}). Exiting..."
return
}
def builds = [:]
stage('Testing') {
for (mach in machinesToRun) {
def machineName = mach
builds[machineName] = {
node(machineName) {
def changedTests = ''
def changedTestsOption
def scratch = sh(returnStdout: true,
script: """${loginBash}
echo \$SCRATCH""").trim()
def reframeDir = "${scratch}/${dirPrefix}-${machineName}-${uniqueID}"
dir("$reframeDir/cscs-reframe-tests") {
checkout scm
changedTests = sh(returnStdout: true,
script: """${loginBash}
git diff origin/main...HEAD --name-only --oneline --no-merges | grep -e '^checks/.*\\.py' || echo 'NOTESTS'""").trim()
changedTestsOption = changedTests == 'NOTESTS' ? '' : changedTests.split().collect { "-c $reframeDir/cscs-reframe-tests/$it" }.join(' ')
changedTestsOption = changedTests == 'NOTESTS' ? '' : "${changedTestsOption}"
}
if (changedTestsOption == '')
return
def configFile = "$reframeDir/cscs-reframe-tests/config/cscs.py"
dir("$reframeDir/reframe") {
checkout([$class: 'GitSCM', branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'WipeWorkspace']], submoduleCfg: [],
userRemoteConfigs: [[url: 'https://github.com/reframe-hpc/reframe.git']]])
def exitStatus = sh(returnStatus: true,
script: """${loginBash}
./bootstrap.sh
export RFM_AUTODETECT_XTHOSTNAME=1
./bin/reframe -C ${configFile} --exec-policy=async --save-log-files -r -J account=jenscscs --flex-alloc-nodes=2 -t 'production|benchmark' $changedTestsOption""")
sh("exit $exitStatus")
}
}
}
}
try {
parallel builds
currentBuild.result = "SUCCESS"
} catch(err) {
if (err.toString().contains('exit code 143')) {
currentBuild.result = "ABORTED"
println "The Unittest was cancelled. Aborting....."
}
else if (err.toString().contains('Queue task was cancelled')) {
currentBuild.result = "ABORTED"
println "The Queue task was cancelled. Aborting....."
}
else {
currentBuild.result = "FAILURE"
println "The Unittest failed. Exiting....."
}
}
}
builds = [:]
stage('Cleanup') {
if (currentBuild.result != 'SUCCESS') {
println 'Not executing "Cleanup" Stage'
return
}
else {
for (mach in machinesToRun) {
def machineName = mach
builds[machineName] = {
node(machineName) {
def scratch = sh(returnStdout: true,
script: """$loginBash
echo \$SCRATCH""").trim()
def reframeDir = "${scratch}/${dirPrefix}-${machineName}-${uniqueID}"
sh("""${loginBash}
rm -rf ${reframeDir}
date""")
}
}
}
try {
parallel builds
currentBuild.result = "SUCCESS"
} catch(err) {
if (err.toString().contains('exit code 143')) {
currentBuild.result = "ABORTED"
println "The Cleanup was cancelled. Aborting....."
}
else if (err.toString().contains('Queue task was cancelled')) {
currentBuild.result = "ABORTED"
println "The Queue task was cancelled. Aborting....."
}
else {
currentBuild.result = "FAILURE"
println "The Cleanup failed. Exiting....."
}
}
}
}
def staleCleanupInterval = 3
builds = [:]
stage('Cleanup Stale') {
for (mach in machinesToRun) {
def machineName = mach
builds[machineName] = {
node(machineName) {
def scratch = sh(returnStdout: true,
script: """${loginBash}
echo \$SCRATCH""").trim()
sh("""${loginBash}
find ${scratch} -maxdepth 1 -name '${dirPrefix}*' -ctime +${staleCleanupInterval} -type d -print0 | xargs -0 printf 'Removing: %s\n'
find ${scratch} -maxdepth 1 -name '${dirPrefix}*' -ctime +${staleCleanupInterval} -type d -print0 | xargs -0 rm -rfv""")
}
}
}
try {
parallel builds
currentBuild.result = "SUCCESS"
} catch(err) {
if (err.toString().contains('exit code 143')) {
currentBuild.result = "ABORTED"
println "The Build step was cancelled. Aborting....."
}
else if (err.toString().contains('Queue task was cancelled')) {
currentBuild.result = "ABORTED"
println "The Queue task was cancelled. Aborting....."
}
else {
currentBuild.result = "FAILURE"
println "The Build step failed. Exiting....."
}
}
}