Extract test results data from [build(job: "child_job")] object

10 views
Skip to first unread message

tre...@gmail.com

unread,
Nov 29, 2018, 4:47:44 AM11/29/18
to Jenkins Users
Hey,

Here is my pipeline landscape:

Master pipeline is triggering smaller child pipelines.

Parent pipeline script snippet:

stage('Integration Tests') {
    steps {
        script {
            def jobs = [:]
            pipelineIntegrationJobs.each {
                i ->
                    jobs["${nirvanaMajor}.${nirvanaMinor}_${i}"] = {
                        def buildInstance = build(job: "${nirvanaMajor}.${nirvanaMinor}_${i}",
                                parameters: [
                                        string(name: 'branch', value: "${svnBranch}", description: 'svn repository url'),
                                        string(name: 'buildmajor', value: '10', description: 'release major identifier'),
                                        string(name: 'buildminor', value: '4', description: 'release minor identifier'),
                                        string(name: 'fix', value: "${env.fix}", description: 'fix level'),
                                        string(name: 'buildnumber', value: "${env.buildNumber}", description: 'artifacts build number'),
                                        string(name: 'revision', value: "${env.buildNumber}", description: 'checkout revision'),
                                        string(name: 'joblabel', value: "${pipelineName}", description: "optional job description")
                                ], quietPeriod: 0, propagate: false, wait: true)
                        def downstreamJobName = "${masterUrl}/job/${nirvanaMajor}.${nirvanaMinor}_${i}/" + buildInstance.number
                        jobStateResults.put(downstreamJobName, buildInstance.result)
                    }
            }
            parallel jobs
        }
    }
}


The child pipeline script uses this method below [getTestResults()] to extract the build test results and it works perfect.

I would like to push this data up to the master pipeline so that I collect all child jobs results.
 
I see the return type of build(job: "child_job") is a RunWrapper (https://javadoc.jenkins.io/plugin/workflow-support/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.html) but how do I extract AbstractTestResultAction from it?


Child pipeline script snippet:
import hudson.tasks.test.AbstractTestResultAction

@NonCPS
def getTestResults () {
def results = [:]
AbstractTestResultAction testResultAction = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
if (testResultAction != null) {
def total = testResultAction.getTotalCount()
def failed = testResultAction.getFailCount()
def skipped = testResultAction.getSkipCount()
def passed = total - failed - skipped
results.put ("Total", total)
results.put ("Passed", passed)
results.put ("Failed", failed)
results.put ("Skipped", skipped)

if (failed == 0) {
currentBuild.result = 'SUCCESS'
}
echo "------------------------------------"
echo "Test Results Summary:"
results.each{ k, v -> echo "${k}: ${v}" }
echo "------------------------------------"
} else {
echo 'No tests results'
}
return results
}

Reply all
Reply to author
Forward
0 new messages