Skip to content

Commit 5874b4f

Browse files
Create Jenkinsfile.metrics
1 parent cabf94b commit 5874b4f

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

.cicd/Jenkinsfile.metrics

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
matchedNode = []
2+
generateBaselineNode = []
3+
for (label in pullRequest.labels) {
4+
listOfLabelNodeNames = jenkins.model.Jenkins.instance.nodes.collect {
5+
node -> node.getLabelString().contains(label) ? node.name : null
6+
7+
if ((label.matches(node.getLabelString()+"-(.*)"))) {
8+
matchedNode += node.getLabelString()
9+
}
10+
11+
if ((label.matches(node.getLabelString()+"(.*)-BL"))) {
12+
generateBaselineNode += node.getLabelString()
13+
}
14+
}
15+
}
16+
17+
modifiedLabels = matchedNode.collect{"'" + it + "'"}
18+
baselineLabels = generateBaselineNode.collect{"'" + it + "'"}
19+
def generateStage(nodeLabel) {
20+
return {
21+
stage("Running on ${nodeLabel}") {
22+
node(nodeLabel) {
23+
cleanWs()
24+
checkout scm
25+
script {
26+
try {
27+
echo "Running on ${nodeLabel}"
28+
if (baselineLabels.contains(nodeLabel)) {
29+
sh '''
30+
31+
git config user.email "ecc.platform@noaa.gov"
32+
git config user.name "epic-cicd-jenkins"
33+
echo "Testing concluded...removing labels for $machine from $GIT_URL"
34+
35+
export machine_name_logs=$(echo $machine | awk '{ print tolower($1) }')
36+
git remote -v | grep -w sshorigin > /dev/null 2>&1 && git remote remove sshorigin > /dev/null 2>&1
37+
git remote add sshorigin $SSH_ORIGIN > /dev/null 2>&1
38+
git add logs/RegressionTests_$machine_name_logs.log
39+
git commit -m "[AutoRT] $machine Job Completed.\n\n\n on-behalf-of @ufs-community <ecc.platform@noaa.gov>"
40+
git pull sshorigin $FORK_BRANCH
41+
git push sshorigin HEAD:$FORK_BRANCH
42+
43+
tar --create --gzip --verbose --dereference --file "${machine_name_logs}.tgz" ${WORKSPACE}/tests/logs/*.log
44+
45+
GIT_OWNER=$(echo $GIT_URL | cut -d '/' -f4)
46+
GIT_REPO_NAME=$(echo $GIT_URL | cut -d '/' -f5 | cut -d '.' -f1)
47+
48+
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
49+
'''
50+
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: []
51+
52+
}
53+
else {
54+
sh '''
55+
56+
git config user.email "ecc.platform@noaa.gov"
57+
git config user.name "epic-cicd-jenkins"
58+
echo "Testing concluded...removing labels for $machine from $GIT_URL"
59+
60+
export machine_name_logs=$(echo $machine | awk '{ print tolower($1) }')
61+
git remote -v | grep -w sshorigin > /dev/null 2>&1 && git remote remove sshorigin > /dev/null 2>&1
62+
git remote add sshorigin $SSH_ORIGIN > /dev/null 2>&1
63+
git add logs/RegressionTests_$machine_name_logs.log
64+
git commit -m "[AutoRT] $machine Job Completed.\n\n\n on-behalf-of @ufs-community <ecc.platform@noaa.gov>"
65+
git pull sshorigin $FORK_BRANCH
66+
git push sshorigin HEAD:$FORK_BRANCH
67+
68+
tar --create --gzip --verbose --dereference --file "${machine_name_logs}.tgz" ${WORKSPACE}/tests/logs/*.log
69+
70+
GIT_OWNER=$(echo $GIT_URL | cut -d '/' -f4)
71+
GIT_REPO_NAME=$(echo $GIT_URL | cut -d '/' -f5 | cut -d '.' -f1)
72+
73+
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
74+
'''
75+
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: []
76+
}
77+
}
78+
catch(err) {
79+
sh '''
80+
export machine=${NODE_NAME}
81+
export CHANGE_ID=${CHANGE_ID}
82+
export SSH_ORIGIN=$(curl --silent https://api.github.com/repos/ufs-community/ufs-weather-model/pulls/$CHANGE_ID | jq -r '.head.repo.ssh_url')
83+
export FORK_BRANCH=$(curl --silent https://api.github.com/repos/ufs-community/ufs-weather-model/pulls/$CHANGE_ID | jq -r '.head.ref')
84+
cd $WORKSPACE/tests
85+
git config user.email "ecc.platform@noaa.gov"
86+
git config user.name "epic-cicd-jenkins"
87+
export machine_name_logs=$(echo $machine | awk '{ print tolower($1) }')
88+
echo "Testing concluded...removing labels for $machine from $GIT_URL"
89+
git remote -v | grep -w sshorigin > /dev/null 2>&1 && git remote remove sshorigin > /dev/null 2>&1
90+
git remote add sshorigin $SSH_ORIGIN > /dev/null 2>&1
91+
92+
tar --create --gzip --verbose --dereference --file "${machine_name_logs}.tgz" ${WORKSPACE}/tests/logs/*.log
93+
94+
GIT_OWNER=$(echo $GIT_URL | cut -d '/' -f4)
95+
GIT_REPO_NAME=$(echo $GIT_URL | cut -d '/' -f5 | cut -d '.' -f1)
96+
97+
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,$machine-BL}
98+
'''
99+
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: []
100+
currentBuild.result = 'FAILURE'
101+
}
102+
}
103+
}
104+
}
105+
}
106+
}
107+
108+
def parallelStagesMap = modifiedLabels.collectEntries {
109+
["${it}" : generateStage(it)]
110+
}
111+
112+
pipeline {
113+
agent none
114+
environment {
115+
ACCNR = 'epic'
116+
AWS_PROD_ACCOUNT_ID = credentials('AWS_PROD_ACCOUNT_ID')
117+
AWS_PROD_SNS_TOPIC = credentials('AWS_PROD_SNS_TOPIC')
118+
GITHUB_TOKEN = credentials('GithubJenkinsNew')
119+
GIT_URL = 'https://github.com/ufs-community/ufs-weather-model.git'
120+
}
121+
stages {
122+
stage('Launch SonarQube') {
123+
steps {
124+
script {
125+
echo "BRANCH_NAME=${env.CHANGE_BRANCH}"
126+
echo "FORK_NAME=${env.CHANGE_FORK}"
127+
echo "CHANGE_URL=${env.CHANGE_URL}"
128+
echo "CHANGE_ID=${env.CHANGE_ID}"
129+
build job: '/ufs-weather-model/ufs-wm-sonarqube', parameters: [
130+
string(name: 'BRANCH_NAME', value: env.CHANGE_BRANCH ?: 'develop'),
131+
string(name: 'FORK_NAME', value: env.CHANGE_FORK ?: ''),
132+
string(name: 'CHANGE_URL', value: env.CHANGE_URL ?: ''),
133+
string(name: 'CHANGE_ID', value: env.CHANGE_ID ?: '')
134+
], wait: false
135+
}
136+
}
137+
}
138+
stage('Run Regression Tests in Parallel') {
139+
steps {
140+
script {
141+
parallel parallelStagesMap
142+
}
143+
}
144+
}
145+
}
146+
post {
147+
success {
148+
node('built-in') {
149+
echo 'This will run only if successful.'
150+
sh '''
151+
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*"}}'
152+
'''
153+
}
154+
}
155+
failure {
156+
node('built-in') {
157+
echo 'This will run only if the run was marked as unstable.'
158+
sh '''
159+
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!*"}}'
160+
'''
161+
}
162+
}
163+
}
164+
}

0 commit comments

Comments
 (0)