aboutsummaryrefslogtreecommitdiff
path: root/jenkins/multi_trigger.groovy
blob: fb65be8ce79de0e4d8a1bb9cf97465abf19d227e (plain) (blame)
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
// Trigger one or more jobs, collect results from each triggered job and e-mail
// a status summary to the recipients defined in the 'email_recipients' job
// parameter.

node('master') {

    tasks = [:]
    build_objs = [:]
    build_types = []
    
    stage("Trigger") {
        for (platform in platforms.tokenize()) {
            build_type = platform.tokenize("_")[0]
            build_types += build_type
            def platname = platform  // must be inside for loop
            println("platname = ${platname}")
            tasks["${platname}"] = {
                build_objs["${platname}"] = build(
                    job: "/AstroConda/${platname}/_dispatch",
                    parameters: [
                        booleanParam(name: 'cull_manifest',
                                     value: cull_manifest.toBoolean()
                        )
                    ],
                    propagate: false)
            } // end tasks
        } // end for
    }
    
    stage("Report") {
        // Parallel execution of the code blocks defined within the 'tasks' map.
        parallel(tasks)
        println("Results...")
        println(build_types)
        results_msg = ""

        compare = build_types[0]
        build_type = compare
        for (type in build_types[1..-1]) {
            if (type != compare) {
                build_type = "mixed"
                break
            }
        }

        platcount = build_objs.size()
        successes = 0
        build_objs.each {
            key, value -> results_msg = "${results_msg}${key} build #: ${value.number}, result: ${value.result}\n"
            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"
    }

}