Skip to content

Commit 061992b

Browse files
Fix Jenkins success reporting (NOAA-EMC#2302)
Moving the post section back outside of main Run Experiments stage. This allows the system to correctly report the **Success** status until after all tests pass. _Had originally moved them in attempts to solve "Not an SCM GitHub Job" issue and cause the reporting to misbehave._ Also ran through Jenkins linter and updated some messaging that was incorrectly reporting system build type.
1 parent 54daa31 commit 061992b

File tree

1 file changed

+77
-77
lines changed

1 file changed

+77
-77
lines changed

Jenkinsfile

+77-77
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ pipeline {
2424
machine = 'none'
2525
for (label in pullRequest.labels) {
2626
echo "Label: ${label}"
27-
if ((label.matches("CI-Hera-Ready"))) {
27+
if ((label.matches('CI-Hera-Ready'))) {
2828
machine = 'hera'
29-
} else if ((label.matches("CI-Orion-Ready"))) {
29+
} else if ((label.matches('CI-Orion-Ready'))) {
3030
machine = 'orion'
31-
} else if ((label.matches("CI-Hercules-Ready"))) {
31+
} else if ((label.matches('CI-Hercules-Ready'))) {
3232
machine = 'hercules'
3333
}
34-
} // createing a second machine varible with first letter capital
35-
// because the first letter of the machine name is captitalized in the GitHub labels
34+
} // createing a second machine varible with first letter capital
35+
// because the first letter of the machine name is captitalized in the GitHub labels
3636
Machine = machine[0].toUpperCase() + machine.substring(1)
3737
}
3838
}
@@ -42,17 +42,17 @@ pipeline {
4242
agent { label "${machine}-emc" }
4343
steps {
4444
script {
45-
properties([parameters([[$class: 'NodeParameterDefinition', allowedSlaves: ['built-in','Hera-EMC','Orion-EMC'], defaultSlaves: ['built-in'], name: '', nodeEligibility: [$class: 'AllNodeEligibility'], triggerIfResult: 'allCases']])])
45+
properties([parameters([[$class: 'NodeParameterDefinition', allowedSlaves: ['built-in', 'Hera-EMC', 'Orion-EMC'], defaultSlaves: ['built-in'], name: '', nodeEligibility: [$class: 'AllNodeEligibility'], triggerIfResult: 'allCases']])])
4646
HOME = "${WORKSPACE}/TESTDIR"
4747
commonworkspace = "${WORKSPACE}"
48-
sh( script: "mkdir -p ${HOME}/RUNTESTS", returnStatus: true)
48+
sh(script: "mkdir -p ${HOME}/RUNTESTS", returnStatus: true)
4949
pullRequest.addLabel("CI-${Machine}-Building")
50-
if ( pullRequest.labels.any{ value -> value.matches("CI-${Machine}-Ready") } ) {
50+
if (pullRequest.labels.any { value -> value.matches("CI-${Machine}-Ready") }) {
5151
pullRequest.removeLabel("CI-${Machine}-Ready")
52-
}
5352
}
5453
}
5554
}
55+
}
5656

5757
stage('Build System') {
5858
matrix {
@@ -61,121 +61,82 @@ pipeline {
6161
// throttle(['global_matrix_build'])
6262
//}
6363
axes {
64-
axis {
65-
name "system"
66-
values "gfs", "gefs"
64+
axis {
65+
name 'system'
66+
values 'gfs', 'gefs'
6767
}
6868
}
6969
stages {
70-
stage("build system") {
70+
stage('build system') {
7171
steps {
7272
script {
7373
def HOMEgfs = "${HOME}/${system}" // local HOMEgfs is used to build the system on per system basis under the common workspace HOME
74-
sh( script: "mkdir -p ${HOMEgfs}", returnStatus: true)
74+
sh(script: "mkdir -p ${HOMEgfs}", returnStatus: true)
7575
ws(HOMEgfs) {
7676
env.MACHINE_ID = machine // MACHINE_ID is used in the build scripts to determine the machine and is added to the shell environment
7777
if (fileExists("${HOMEgfs}/sorc/BUILT_semaphor")) { // if the system is already built, skip the build in the case of re-runs
78-
sh( script: "cat ${HOMEgfs}/sorc/BUILT_semaphor", returnStdout: true).trim() // TODO: and user configurable control to manage build semphore
78+
sh(script: "cat ${HOMEgfs}/sorc/BUILT_semaphor", returnStdout: true).trim() // TODO: and user configurable control to manage build semphore
7979
ws(commonworkspace) { pullRequest.comment("Cloned PR already built (or build skipped) on ${machine} in directory ${HOMEgfs}") }
8080
} else {
8181
checkout scm
82-
sh( script: "source workflow/gw_setup.sh;which git;git --version;git submodule update --init --recursive", returnStatus: true)
83-
def builds_file = readYaml file: "ci/cases/yamls/build.yaml"
82+
sh(script: 'source workflow/gw_setup.sh;which git;git --version;git submodule update --init --recursive', returnStatus: true)
83+
def builds_file = readYaml file: 'ci/cases/yamls/build.yaml'
8484
def build_args_list = builds_file['builds']
85-
def build_args = build_args_list[system].join(" ").trim().replaceAll("null", "")
85+
def build_args = build_args_list[system].join(' ').trim().replaceAll('null', '')
8686
dir("${HOMEgfs}/sorc") {
87-
sh( script: "${build_args}", returnStatus: true)
88-
sh( script: "./link_workflow.sh", returnStatus: true)
89-
sh( script: "echo ${HOMEgfs} > BUILT_semaphor", returnStatus: true)
87+
sh(script: "${build_args}", returnStatus: true)
88+
sh(script: './link_workflow.sh', returnStatus: true)
89+
sh(script: "echo ${HOMEgfs} > BUILT_semaphor", returnStatus: true)
9090
}
9191
}
92-
if ( pullRequest.labels.any{ value -> value.matches("CI-${Machine}-Building") } ) {
93-
pullRequest.removeLabel("CI-${Machine}-Building")
94-
}
95-
pullRequest.addLabel("CI-${Machine}-Running")
92+
if (pullRequest.labels.any { value -> value.matches("CI-${Machine}-Building") }) {
93+
pullRequest.removeLabel("CI-${Machine}-Building")
9694
}
95+
pullRequest.addLabel("CI-${Machine}-Running")
9796
}
9897
}
9998
}
10099
}
101100
}
102101
}
102+
}
103103

104104
stage('Run Tests') {
105105
matrix {
106106
agent { label "${machine}-emc" }
107107
axes {
108108
axis {
109-
name "Case"
110-
values "C48_ATM", "C48_S2SWA_gefs", "C48_S2SW", "C96_atm3DVar" // TODO add dynamic list of cases from env vars (needs addtional plugins)
109+
name 'Case'
110+
values 'C48_ATM', 'C48_S2SWA_gefs', 'C48_S2SW', 'C96_atm3DVar' // TODO add dynamic list of cases from env vars (needs addtional plugins)
111111
}
112112
}
113113
stages {
114114
stage('Create Experiment') {
115-
steps {
115+
steps {
116116
script {
117-
sh( script: "sed -n '/{.*}/!p' ${HOME}/gfs/ci/cases/pr/${Case}.yaml > ${HOME}/gfs/ci/cases/pr/${Case}.yaml.tmp", returnStatus: true)
117+
sh(script: "sed -n '/{.*}/!p' ${HOME}/gfs/ci/cases/pr/${Case}.yaml > ${HOME}/gfs/ci/cases/pr/${Case}.yaml.tmp", returnStatus: true)
118118
def yaml_case = readYaml file: "${HOME}/gfs/ci/cases/pr/${Case}.yaml.tmp"
119119
system = yaml_case.experiment.system
120120
def HOMEgfs = "${HOME}/${system}" // local HOMEgfs is used to populate the XML on per system basis
121121
env.RUNTESTS = "${HOME}/RUNTESTS"
122-
sh( script: "${HOMEgfs}/ci/scripts/utils/ci_utils_wrapper.sh create_experiment ${HOMEgfs}/ci/cases/pr/${Case}.yaml", returnStatus: true)
123-
}
122+
sh(script: "${HOMEgfs}/ci/scripts/utils/ci_utils_wrapper.sh create_experiment ${HOMEgfs}/ci/cases/pr/${Case}.yaml", returnStatus: true)
123+
}
124124
}
125125
}
126126
stage('Run Experiments') {
127127
steps {
128128
script {
129129
HOMEgfs = "${HOME}/gfs" // common HOMEgfs is used to launch the scripts that run the experiments
130130
ws(HOMEgfs) {
131-
pslot = sh( script: "${HOMEgfs}/ci/scripts/utils/ci_utils_wrapper.sh get_pslot ${HOME}/RUNTESTS ${Case}", returnStdout: true ).trim()
132-
pullRequest.comment("**Running experiments: ${Case} on ${Machine}**<br>Built against system **${system}** in directory:<br>`${HOMEgfs}`<br>With the experiment in directory:<br>`${HOME}/RUNTESTS/${pslot}`")
133-
try {
134-
sh( script: "${HOMEgfs}/ci/scripts/run-check_ci.sh ${HOME} ${pslot}", returnStatus: true)
131+
pslot = sh(script: "${HOMEgfs}/ci/scripts/utils/ci_utils_wrapper.sh get_pslot ${HOME}/RUNTESTS ${Case}", returnStdout: true).trim()
132+
pullRequest.comment("**Running** experiment: ${Case} on ${Machine}<br>With the experiment in directory:<br>`${HOME}/RUNTESTS/${pslot}`")
133+
try {
134+
sh(script: "${HOMEgfs}/ci/scripts/run-check_ci.sh ${HOME} ${pslot}", returnStatus: true)
135135
} catch (Exception e) {
136-
pullRequest.comment("**FAILURE** running experiments: ${Case} on ${Machine}")
137-
error("Failed to run experiments ${Case} on ${Machine}")
138-
}
139-
pullRequest.comment("**SUCCESS** running experiments: ${Case} on ${Machine}")
140-
}
141-
}
142-
}
143-
post {
144-
always {
145-
script {
146-
ws (HOMEgfs) {
147-
for (label in pullRequest.labels) {
148-
if (label.contains("${Machine}")) {
149-
pullRequest.removeLabel(label)
150-
}
151-
}
152-
}
153-
}
154-
}
155-
success {
156-
script {
157-
ws (HOMEgfs) {
158-
pullRequest.addLabel("CI-${Machine}-Passed")
159-
def timestamp = new Date().format("MM dd HH:mm:ss", TimeZone.getTimeZone('America/New_York'))
160-
pullRequest.comment("**CI SUCCESS** ${Machine} at ${timestamp}\n\nBuilt and ran in directory `${HOME}`")
161-
}
162-
}
163-
}
164-
failure {
165-
script {
166-
ws (HOMEgfs) {
167-
pullRequest.addLabel("CI-${Machine}-Failed")
168-
def timestamp = new Date().format("MM dd HH:mm:ss", TimeZone.getTimeZone('America/New_York'))
169-
pullRequest.comment("**CI FAILED** ${Machine} at ${timestamp}<br>Built and ran in directory `${HOME}`")
170-
if (fileExists('${HOME}/RUNTESTS/ci.log')) {
171-
def fileContent = readFile '${HOME}/RUNTESTS/ci.log'
172-
fileContent.eachLine { line ->
173-
if( line.contains(".log")) {
174-
archiveArtifacts artifacts: "${line}", fingerprint: true
175-
}
176-
}
177-
}
136+
pullRequest.comment("**FAILURE** running experiment: ${Case} on ${Machine}")
137+
error("Failed to run experiments ${Case} on ${Machine}")
178138
}
139+
pullRequest.comment("**SUCCESS** running experiment: ${Case} on ${Machine}")
179140
}
180141
}
181142
}
@@ -185,4 +146,43 @@ pipeline {
185146
}
186147
}
187148

149+
post {
150+
always {
151+
script {
152+
if(env.CHANGE_ID) {
153+
for (label in pullRequest.labels) {
154+
if (label.contains("${Machine}")) {
155+
pullRequest.removeLabel(label)
156+
}
157+
}
158+
}
159+
}
160+
}
161+
success {
162+
script {
163+
if(env.CHANGE_ID) {
164+
pullRequest.addLabel("CI-${Machine}-Passed")
165+
def timestamp = new Date().format('MM dd HH:mm:ss', TimeZone.getTimeZone('America/New_York'))
166+
pullRequest.comment("**CI SUCCESS** ${Machine} at ${timestamp}\n\nBuilt and ran in directory `${HOME}`")
167+
}
168+
}
169+
}
170+
failure {
171+
script {
172+
if(env.CHANGE_ID) {
173+
pullRequest.addLabel("CI-${Machine}-Failed")
174+
def timestamp = new Date().format('MM dd HH:mm:ss', TimeZone.getTimeZone('America/New_York'))
175+
pullRequest.comment("**CI FAILED** ${Machine} at ${timestamp}<br>Built and ran in directory `${HOME}`")
176+
}
177+
if (fileExists('${HOME}/RUNTESTS/ci.log')) {
178+
def fileContent = readFile '${HOME}/RUNTESTS/ci.log'
179+
fileContent.eachLine { line ->
180+
if (line.contains('.log')) {
181+
archiveArtifacts artifacts: "${line}", fingerprint: true
182+
}
183+
}
184+
}
185+
}
186+
}
187+
}
188188
}

0 commit comments

Comments
 (0)