-
Notifications
You must be signed in to change notification settings - Fork 239
/
Jenkinsfile.combined
390 lines (368 loc) · 22.7 KB
/
Jenkinsfile.combined
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
matchedNode = []
generateBaselineNode = []
for (label in pullRequest.labels) {
listOfLabelNodeNames = jenkins.model.Jenkins.instance.nodes.collect {
node -> node.getLabelString().contains(label) ? node.name : null
if ((label.matches(node.getLabelString()+"-(.*)"))) {
matchedNode += node.getLabelString()
}
if ((label.matches(node.getLabelString()+"(.*)-BL"))) {
generateBaselineNode += node.getLabelString()
}
}
}
modifiedLabels = matchedNode.collect{"'" + it + "'"}
baselineLabels = generateBaselineNode.collect{"'" + it + "'"}
def generateStage(nodeLabel) {
return {
stage("Running on ${nodeLabel}") {
node(nodeLabel) {
cleanWs()
checkout scm
script {
try {
echo "Running on ${nodeLabel}"
if (baselineLabels.contains(nodeLabel)) {
sh '''
git submodule update --init --recursive
cd tests
pwd
export BL_DATE=$(cat bl_date.conf | cut -d '=' -f2)
export machine=${NODE_NAME}
export PATH=$PATH:~/bin
echo $CHANGE_ID
export SSH_ORIGIN=$(curl --silent https://api.github.com/repos/ufs-community/ufs-weather-model/pulls/$CHANGE_ID | jq -r '.head.repo.ssh_url')
export FORK_BRANCH=$(curl --silent https://api.github.com/repos/ufs-community/ufs-weather-model/pulls/$CHANGE_ID | jq -r '.head.ref')
if [[ $machine =~ "Jet" ]]
then
echo "Creating baselines on $machine"
export dprefix=/lfs1/NAGAPE/$ACCNR/$USER
./rt.sh -a ${ACCNR} -c -r -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
elif [[ $machine =~ "Hercules" ]]
then
echo "Creating baselines on $machine"
export dprefix=/work2/noaa/$ACCNR/$USER
sed "s|/noaa/stmp/|/noaa/$ACCNR/stmp/|g" -i rt.sh
export ACCNR=epic
./rt.sh -a ${ACCNR} -c -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
export DISKNM=/work/noaa/epic/hercules/UFS-WM_RT
cd ${DISKNM}/NEMSfv3gfs/
mkdir develop-${BL_DATE}
cd /work2/noaa/epic/stmp/role-epic/stmp/role-epic/FV3_RT
rsync -a REGRESSION_TEST/ ${DISKNM}/NEMSfv3gfs/develop-${BL_DATE}
cd ${DISKNM}/NEMSfv3gfs/
./adjust_permissions.sh hercules develop-${BL_DATE}
chgrp noaa-hpc develop-${BL_DATE}
cd $WORKSPACE/tests
./rt.sh -a ${ACCNR} -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
cd logs/
cp RegressionTests_hercules.log /work/noaa/epic/role-epic/jenkins/workspace
git remote -v
git fetch --no-recurse-submodules origin
git reset FETCH_HEAD --hard
cd .. && cd .. && cd ..
cp RegressionTests_hercules.log $WORKSPACE/tests/logs/
cd $WORKSPACE/tests/
elif [[ $machine =~ "Orion" ]]
then
cd ..
module load git/2.28.0
git submodule update --init --recursive
cd tests
echo "Creating baselines on $machine"
export dprefix=/work2/noaa/$ACCNR/$USER
sed -i 's|/work/noaa/stmp/${USER}|/work/noaa/epic/stmp/role-epic/|g' rt.sh
export ACCNR=epic
./rt.sh -a ${ACCNR} -c -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
export DISKNM=/work/noaa/epic/UFS-WM_RT
cd ${DISKNM}/NEMSfv3gfs/
mkdir develop-${BL_DATE}
cd /work/noaa/epic/stmp/role-epic/stmp/role-epic/FV3_RT/
rsync -a REGRESSION_TEST/ ${DISKNM}/NEMSfv3gfs/develop-${BL_DATE}
cd ${DISKNM}/NEMSfv3gfs/
./adjust_permissions.sh orion develop-${BL_DATE}
chgrp noaa-hpc develop-${BL_DATE}
cd $WORKSPACE/tests
./rt.sh -a ${ACCNR} -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
cd logs/
cp RegressionTests_orion.log /work/noaa/epic/role-epic/jenkins/workspace
git remote -v
git fetch --no-recurse-submodules origin
git reset FETCH_HEAD --hard
cd .. && cd .. && cd ..
cp RegressionTests_orion.log $WORKSPACE/tests/logs/
cd $WORKSPACE/tests/
elif [[ $machine =~ "Gaea" ]]
then
echo "Creating baselines on $machine"
./rt.sh -a ${ACCNR} -c -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
unset LD_LIBRARY_PATH
export DISKNM=/gpfs/f5/epic/world-shared/UFS-WM_RT
cd ${DISKNM}/NEMSfv3gfs/
mkdir develop-${BL_DATE}
cd /gpfs/f5/epic/scratch/role.epic/FV3_RT
rsync -a REGRESSION_TEST/ ${DISKNM}/NEMSfv3gfs/develop-${BL_DATE}
cd ${DISKNM}/NEMSfv3gfs/
chgrp ncep develop-${BL_DATE}
cd $WORKSPACE/tests
./rt.sh -a ${ACCNR} -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
cd logs/
cp RegressionTests_gaea.log /gpfs/f5/epic/scratch/role.epic/jenkins/workspace
git remote -v
git fetch --no-recurse-submodules origin
git reset FETCH_HEAD --hard
cd .. && cd .. && cd ..
cp RegressionTests_gaea.log $WORKSPACE/tests/logs/
cd $WORKSPACE/tests/
elif [[ $machine =~ "Hera" ]]
then
echo "Creating baselines on $machine"
export ACCNR=epic
./rt.sh -a ${ACCNR} -c -r -l rt.conf
export DISKNM=/scratch2/NAGAPE/epic/UFS-WM_RT
cd ${DISKNM}/NEMSfv3gfs/
mkdir develop-${BL_DATE}
cd /scratch1/NCEPDEV/stmp4/role.epic/FV3_RT
rsync -a REGRESSION_TEST/ ${DISKNM}/NEMSfv3gfs/develop-${BL_DATE}
cd $WORKSPACE/tests
./rt.sh -a ${ACCNR} -r -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
cd logs/
cp RegressionTests_hera.log /scratch2/NAGAPE/epic/role.epic/jenkins/workspace
git remote -v
git fetch --no-recurse-submodules origin
git reset FETCH_HEAD --hard
cd .. && cd .. && cd ..
cp RegressionTests_hera.log $WORKSPACE/tests/logs/
cd $WORKSPACE/tests/
elif [[ $machine =~ "Derecho" ]]
then
echo "Creating baselines on $machine"
export ACCNR=nral0032
./rt.sh -a ${ACCNR} -c -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
export DISKNM=/glade/derecho/scratch/epicufsrt/ufs-weather-model/RT/
cd ${DISKNM}/NEMSfv3gfs/
mkdir develop-${BL_DATE}
cd /glade/derecho/scratch/epicufsrt/FV3_RT
rsync -a REGRESSION_TEST/ ${DISKNM}/NEMSfv3gfs/develop-${BL_DATE}
cd $WORKSPACE/tests
./rt.sh -a ${ACCNR} -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
cd logs/
cp RegressionTests_derecho.log /glade/derecho/scratch/epicufsrt/jenkins/workspace
git remote -v
git fetch --no-recurse-submodules origin
git reset FETCH_HEAD --hard
cd .. && cd .. && cd ..
cp RegressionTests_derecho.log $WORKSPACE/tests/logs/
cd $WORKSPACE/tests/
else
echo "Creating baselines on $machine"
./rt.sh -a ${ACCNR} -c -r -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
fi
git config user.email "[email protected]"
git config user.name "epic-cicd-jenkins"
echo "Testing concluded...removing labels for $machine from $GIT_URL"
export machine_name_logs=$(echo $machine | awk '{ print tolower($1) }')
git remote -v | grep -w sshorigin > /dev/null 2>&1 && git remote remove sshorigin > /dev/null 2>&1
git remote add sshorigin $SSH_ORIGIN > /dev/null 2>&1
git add logs/RegressionTests_$machine_name_logs.log
git commit -m "[AutoRT] $machine Job Completed.\n\n\n on-behalf-of @ufs-community <[email protected]>"
git pull sshorigin $FORK_BRANCH
git push sshorigin HEAD:$FORK_BRANCH
tar --create --gzip --verbose --dereference --file "${machine_name_logs}.tgz" ${WORKSPACE}/tests/logs/*.log
GIT_OWNER=$(echo $GIT_URL | cut -d '/' -f4)
GIT_REPO_NAME=$(echo $GIT_URL | cut -d '/' -f5 | cut -d '.' -f1)
curl --silent -X DELETE -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" https://api.github.com/repos/${GIT_OWNER}/${GIT_REPO_NAME}/issues/${CHANGE_ID}/labels/$machine-BL
'''
s3Upload consoleLogLevel: 'INFO', dontSetBuildResultOnFailure: false, dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'noaa-epic-prod-jenkins-artifacts', excludedFile: '', flatten: true, gzipFiles: false, keepForever: false, managedArtifacts: true, noUploadOnFailure: false, selectedRegion: 'us-east-1', showDirectlyInBrowser: false, sourceFile: "**/*tgz*", storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 'main', userMetadata: []
}
else {
sh '''
git submodule update --init --recursive
pwd
cd tests
export machine=${NODE_NAME}
export PATH=$PATH:~/bin
echo $CHANGE_ID
export SSH_ORIGIN=$(curl --silent https://api.github.com/repos/ufs-community/ufs-weather-model/pulls/$CHANGE_ID | jq -r '.head.repo.ssh_url')
export FORK_BRANCH=$(curl --silent https://api.github.com/repos/ufs-community/ufs-weather-model/pulls/$CHANGE_ID | jq -r '.head.ref')
if [[ $machine =~ "Jet" ]]
then
echo "Running regression tests on $machine"
export dprefix=/lfs1/NAGAPE/$ACCNR/$USER
./rt.sh -a ${ACCNR} -r -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
elif [[ $machine =~ "Hercules" ]]
then
echo "Running regression tests on $machine"
export dprefix=/work2/noaa/$ACCNR/$USER
sed "s|/noaa/stmp/|/noaa/$ACCNR/stmp/|g" -i rt.sh
export ACCNR=epic
./rt.sh -a ${ACCNR} -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
cd logs/
cp RegressionTests_hercules.log /work/noaa/epic/role-epic/jenkins/workspace
git remote -v
git fetch --no-recurse-submodules origin
git reset FETCH_HEAD --hard
cd .. && cd .. && cd ..
cp RegressionTests_hercules.log $WORKSPACE/tests/logs/
cd $WORKSPACE/tests/
elif [[ $machine =~ "Orion" ]]
then
echo "Running regression tests on $machine"
cd ..
module load git/2.28.0
git submodule update --init --recursive
cd tests
export dprefix=/work2/noaa/$ACCNR/$USER
sed "s|/noaa/stmp/|/noaa/$ACCNR/stmp/|g" -i rt.sh
./rt.sh -a ${ACCNR} -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
cd logs/
cp RegressionTests_orion.log /work/noaa/epic/role-epic/jenkins/workspace
git remote -v
git fetch --no-recurse-submodules origin
git reset FETCH_HEAD --hard
cd .. && cd .. && cd ..
cp RegressionTests_orion.log $WORKSPACE/tests/logs/
cd $WORKSPACE/tests/
elif [[ $machine =~ "Gaea" ]]
then
echo "Running regression tests on $machine"
./rt.sh -a ${ACCNR} -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
unset LD_LIBRARY_PATH
cd logs/
cp RegressionTests_gaea.log /gpfs/f5/epic/scratch/role.epic/jenkins/workspace
git remote -v
git fetch --no-recurse-submodules origin
git reset FETCH_HEAD --hard
cd .. && cd .. && cd ..
cp RegressionTests_gaea.log $WORKSPACE/tests/logs/
cd $WORKSPACE/tests/
elif [[ $machine =~ "Hera" ]]
then
echo "Running regression tests on $machine"
export ACCNR=epic
./rt.sh -a ${ACCNR} -r -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
cd logs/
cp RegressionTests_hera.log /scratch2/NAGAPE/epic/role.epic/jenkins/workspace
git remote -v
git fetch --no-recurse-submodules origin
git reset FETCH_HEAD --hard
cd .. && cd .. && cd ..
cp RegressionTests_hera.log $WORKSPACE/tests/logs/
cd $WORKSPACE/tests/
elif [[ $machine =~ "Derecho" ]]
then
echo "Running regression tests on $machine"
export ACCNR=nral0032
./rt.sh -a ${ACCNR} -e -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
cd logs/
cp RegressionTests_derecho.log /glade/derecho/scratch/epicufsrt/jenkins/workspace
git remote -v
git fetch --no-recurse-submodules origin
git reset FETCH_HEAD --hard
cd .. && cd .. && cd ..
cp RegressionTests_derecho.log $WORKSPACE/tests/logs/
cd $WORKSPACE/tests/
else
echo "Running regression tests on $machine"
./rt.sh -a ${ACCNR} -r -l rt.conf | tee $WORKSPACE/tests/logs/RT-run-$machine.log
fi
git config user.email "[email protected]"
git config user.name "epic-cicd-jenkins"
export machine_name_logs=$(echo $machine | awk '{ print tolower($1) }')
echo "Testing concluded...removing labels for $machine from $GIT_URL"
git remote -v | grep -w sshorigin > /dev/null 2>&1 && git remote remove sshorigin > /dev/null 2>&1
git remote add sshorigin $SSH_ORIGIN > /dev/null 2>&1
git add logs/RegressionTests_$machine_name_logs.log
git commit -m "[AutoRT] $machine Job Completed.\n\n\n on-behalf-of @ufs-community <[email protected]>"
git pull sshorigin $FORK_BRANCH
git push sshorigin HEAD:$FORK_BRANCH
tar --create --gzip --verbose --dereference --file "${machine_name_logs}.tgz" ${WORKSPACE}/tests/logs/*.log
GIT_OWNER=$(echo $GIT_URL | cut -d '/' -f4)
GIT_REPO_NAME=$(echo $GIT_URL | cut -d '/' -f5 | cut -d '.' -f1)
curl --silent -X DELETE -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" https://api.github.com/repos/${GIT_OWNER}/${GIT_REPO_NAME}/issues/${CHANGE_ID}/labels/$machine-RT
'''
s3Upload consoleLogLevel: 'INFO', dontSetBuildResultOnFailure: false, dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'noaa-epic-prod-jenkins-artifacts', excludedFile: '', flatten: true, gzipFiles: false, keepForever: false, managedArtifacts: true, noUploadOnFailure: false, selectedRegion: 'us-east-1', showDirectlyInBrowser: false, sourceFile: "**/*tgz*", storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 'main', userMetadata: []
}
}
catch(err) {
sh '''
export machine=${NODE_NAME}
export CHANGE_ID=${CHANGE_ID}
export SSH_ORIGIN=$(curl --silent https://api.github.com/repos/ufs-community/ufs-weather-model/pulls/$CHANGE_ID | jq -r '.head.repo.ssh_url')
export FORK_BRANCH=$(curl --silent https://api.github.com/repos/ufs-community/ufs-weather-model/pulls/$CHANGE_ID | jq -r '.head.ref')
cd $WORKSPACE/tests
git config user.email "[email protected]"
git config user.name "epic-cicd-jenkins"
export machine_name_logs=$(echo $machine | awk '{ print tolower($1) }')
echo "Testing concluded...removing labels for $machine from $GIT_URL"
git remote -v | grep -w sshorigin > /dev/null 2>&1 && git remote remove sshorigin > /dev/null 2>&1
git remote add sshorigin $SSH_ORIGIN > /dev/null 2>&1
if [[ -f $WORKSPACE/tests/logs/RT-run-$machine.log ]] ; then
git add $WORKSPACE/tests/logs/RT-run-$machine.log
fi
git commit --allow-empty -m "[AutoRT] $machine Job Failed!\n\n\n on-behalf-of @ufs-community <[email protected]>"
git pull sshorigin $FORK_BRANCH
git push sshorigin HEAD:$FORK_BRANCH
tar --create --gzip --verbose --dereference --file "${machine_name_logs}.tgz" ${WORKSPACE}/tests/logs/*.log
GIT_OWNER=$(echo $GIT_URL | cut -d '/' -f4)
GIT_REPO_NAME=$(echo $GIT_URL | cut -d '/' -f5 | cut -d '.' -f1)
curl --silent -X DELETE -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" https://api.github.com/repos/${GIT_OWNER}/${GIT_REPO_NAME}/issues/${CHANGE_ID}/labels -d '{"labels":["$machine-.*RT|$machine-.*BL"]}'
'''
s3Upload consoleLogLevel: 'INFO', dontSetBuildResultOnFailure: false, dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'noaa-epic-prod-jenkins-artifacts', excludedFile: '', flatten: true, gzipFiles: false, keepForever: false, managedArtifacts: true, noUploadOnFailure: false, selectedRegion: 'us-east-1', showDirectlyInBrowser: false, sourceFile: "**/*tgz*", storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 'main', userMetadata: []
currentBuild.result = 'FAILURE'
}
}
}
}
}
}
def parallelStagesMap = modifiedLabels.collectEntries {
["${it}" : generateStage(it)]
}
pipeline {
agent none
environment {
ACCNR = 'epic'
AWS_PROD_ACCOUNT_ID = credentials('AWS_PROD_ACCOUNT_ID')
AWS_PROD_SNS_TOPIC = credentials('AWS_PROD_SNS_TOPIC')
GITHUB_TOKEN = credentials('GithubJenkinsNew')
GIT_URL = 'https://github.com/ufs-community/ufs-weather-model.git'
}
stages {
stage('Run SonarQube Testing') {
steps {
script {
build job: '/ufs-weather-model/ufs-wm-sonarqube', parameters: [
string(name: 'BRANCH_NAME', value: env.CHANGE_BRANCH ?: 'develop'),
string(name: 'FORK_NAME', value: env.CHANGE_FORK ?: '')
], wait: false
}
}
}
stage('Run Regression Tests in Parallel') {
steps {
script {
parallel parallelStagesMap
}
}
}
}
post {
success {
node('built-in') {
echo 'This will run only if successful.'
sh '''
aws sns publish --topic-arn "arn:aws:sns:us-east-1:${AWS_PROD_ACCOUNT_ID}:${AWS_PROD_SNS_TOPIC}" --region us-east-1 --message '{"version":"1.0","source":"custom","content":{"description":":sunny: Jenkins build *'"$JOB_NAME"' '"$BUILD_NUMBER"'* with *PR-'"$CHANGE_ID"'* *succeeded*"}}'
'''
}
}
failure {
node('built-in') {
echo 'This will run only if the run was marked as unstable.'
sh '''
aws sns publish --topic-arn "arn:aws:sns:us-east-1:${AWS_PROD_ACCOUNT_ID}:${AWS_PROD_SNS_TOPIC}" --region us-east-1 --message '{"version":"1.0","source":"custom","content":{"description":":warning: Jenkins build *'"$JOB_NAME"' '"$BUILD_NUMBER"'* with *PR-'"$CHANGE_ID"'* *failed!*"}}'
'''
}
}
}
}