1

How can I get the status of already completed builds?

The code below starts the build, but I just need to know the build status by name. I need to find out the names of the failed builds in order to send the data in one message to the mail.

Map buildResults = [:]

Boolean failedJobs = false

void nofify_email(Map results) {
    echo "TEST SIMULATE notify: ${results.toString()}"
}

Boolean buildJob(String jobName, Map results) {

    def jobBuild = **build job: jobName**, propagate: false

    def jobResult = jobBuild.getResult()

    echo "Build of '${jobName}' returned result: ${jobResult}"

    results[jobName] = jobResult

    return jobResult == 'SUCCESS'
}
pipeline {

    agent any

    stages {

        stage('Parallel Builds') {

            steps {

                parallel(

                        "testJob1": {
                            script {
                                if (!buildJob('testJob1', buildResults)) {
                                    failedJobs = true
                                }
                            }
                        },
                )
            }
        }

I couldn't find anything to replace build job

Andrej Istomin
  • 2,527
  • 2
  • 15
  • 22
Flint
  • 11
  • 1
  • See [this answer](https://stackoverflow.com/a/73995884/1655780). "build" is the step to build a job by name. build returns an object with a ".result" property that you can interrogate directly... assuming you let the job complete (wait: false). – Steven the Easily Amused Feb 13 '23 at 18:59

0 Answers0