aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Rendina <rendinam@users.noreply.github.com>2018-04-06 11:15:37 -0400
committerGitHub <noreply@github.com>2018-04-06 11:15:37 -0400
commit3ca4348476ea9150e98468f462189c594903ae82 (patch)
tree917f4464eed169a622f90ac8421a9a279e7bacc7
parent28eb9198885f8350df153bb48f4e6adfe6120166 (diff)
downloadbuild_control-3ca4348476ea9150e98468f462189c594903ae82.tar.gz
Mail suppression and related bugfixes (#61)1.0.23
* Remove deprecated triggering method. * Suppress e-mail when mail_recipients is empty * Handle single job suite builds correctly. * Use dispatch job's success status when summing successes.
-rw-r--r--jenkins/multi_trigger.groovy30
-rw-r--r--jenkins/scheduled_trigger.groovy76
2 files changed, 19 insertions, 87 deletions
diff --git a/jenkins/multi_trigger.groovy b/jenkins/multi_trigger.groovy
index fb65be8..1e9d9fd 100644
--- a/jenkins/multi_trigger.groovy
+++ b/jenkins/multi_trigger.groovy
@@ -30,35 +30,43 @@ node('master') {
stage("Report") {
// Parallel execution of the code blocks defined within the 'tasks' map.
parallel(tasks)
+
println("Results...")
- println(build_types)
results_msg = ""
+ // Determine if all build types are the same, or if this was a mixed-type build.
compare = build_types[0]
build_type = compare
- for (type in build_types[1..-1]) {
- if (type != compare) {
- build_type = "mixed"
- break
+ if (build_types.size() > 1) {
+ for (type in build_types[1..-1]) {
+ if (type != compare) {
+ build_type = "mixed"
+ break
+ }
}
}
+ // Compose status summary. Send mail if recipients have been specified.
platcount = build_objs.size()
successes = 0
build_objs.each {
key, value -> results_msg = "${results_msg}${key} build #: ${value.number}, result: ${value.result}\n"
+ if (value.result == "SUCCESS") {
+ successes++
+ }
for (pkg_result in value.description.split('\n')) {
- if (pkg_result == "SUCCESS") {
- successes++
- }
results_msg = "${results_msg}${pkg_result}\n"
}
results_msg = "${results_msg}\n"
}
println(results_msg)
- def recipients = mail_recipients.replaceAll("\n", " ")
- def subject = "Build summary, ${build_type} - ${successes}/${platcount} platforms successful"
- mail body: results_msg, subject: subject, to: recipients, from: "jenkins@boyle.stsci.edu"
+ def recipients = mail_recipients.replaceAll("\n", " ").trim()
+ if (recipients != "") {
+ def subject = "Build summary, ${build_type} - ${successes}/${platcount} platforms successful"
+ mail body: results_msg, subject: subject, to: recipients, from: "jenkins@boyle.stsci.edu"
+ } else {
+ println("e-mail not sent: No recipients specified.")
+ }
}
}
diff --git a/jenkins/scheduled_trigger.groovy b/jenkins/scheduled_trigger.groovy
deleted file mode 100644
index d1a5296..0000000
--- a/jenkins/scheduled_trigger.groovy
+++ /dev/null
@@ -1,76 +0,0 @@
-// Triggers the execution of one or more jobs found within 'abs_jobs_folder'.
-//
-// This job may be scheduled to run at particular intervals to schedule
-// collections of jobs simultaneously.
-//
-// Parameters to be passed to the triggered jobs are defined in the job
-// configuration interface within Jenkins.
-// PLATFORMS
-// abs_jobs_folder
-//
-// Parameter names that are prefixed by the text appearing as the value of
-// 'this.job_param_id' will be passed along as run parameters to each job
-// that this job triggers.
-
-this.job_param_id = "(downstream)"
-
-node("master") {
-
- // Print version info
- build_control_repo = scm.getUserRemoteConfigs()[0].getUrl()
- build_control_bt_spec = scm.branches[0].toString()
- if (build_control_bt_spec.find("tags") != null) {
- build_control_branch = "master"
- build_control_tag = build_control_bt_spec.tokenize("/")[-1]
- } else { // a branch, including */master
- build_control_branch = build_control_bt_spec.tokenize("/")[-1]
- }
- println("Build control repo: ${build_control_repo}")
- println("Build control branch: ${build_control_branch}")
-
- // From Credentials Binding plugin:
- withCredentials([usernamePassword(credentialsId: 'ScopedJenkinsLocal',
- usernameVariable: 'USERNAME',
- passwordVariable: 'PASSWORD')]) {
-
- println(params)
- // Collect the parameters to pass along to triggered jobs (as opposed
- // to parameters used to control the behavior of this job). Compose
- // the URL string used to pass those parameter values to the jobs
- // being triggered via the REST API.
- params_url = ""
- params.each {
- key = it.key.toString()
- val = it.value.toString()
- if (key.find(this.job_param_id) != null) {
- println("${key}, ${val}")
- index = this.job_param_id.size()
- param_name = key[index..-1].trim()
- println(param_name)
- params_url = "${params_url}${param_name}=${val}\\&"
- println("LOOP params_url: ${params_url}")
- }
- }
-
- // Obtain authentication "crumb" for this session.
- url_base = env.JENKINS_URL.split("://")[1]
- crumb_url_path = "crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)"
- crumb_url = "http://${USERNAME}:${PASSWORD}@${url_base}/${crumb_url_path}"
- CRUMB = sh (script: "curl -s '${crumb_url}'", returnStdout: true).trim()
- println("CRUMB: ${CRUMB}")
-
- // Trigger all requested jobs with supplied parameter(s).
- println("Platforms:\n${PLATFORMS}")
- for (platform in PLATFORMS.tokenize()) {
- println("Triggering _dispatch job for ${platform}...")
- //trigger_url = "http://${url_base}/job/${abs_jobs_folder}/job/${platform}/" +
- // "job/_dispatch/buildWithParameters${params_url} " +
- // "-u ${USERNAME}:${PASSWORD}"
- trigger_url = "http://${url_base}/job/${abs_jobs_folder}/job/${platform}/" +
- "job/_dispatch/buildWithParameters?${params_url} " +
- "-u ${USERNAME}:${PASSWORD}"
- println(trigger_url)
- sh (script: "curl -s -S -X POST -H ${CRUMB} ${trigger_url}")
- }
- }
-}