I am executing 3 parallel jobs, each that run tests, from my job as follows:
def run_job(job) {
output = build(job:job, parameters:parameters)
def buildNumber = output.getNumber().toString()
test_results[job] = '/job/'+ job +'/' + buildNumber + '/artifact/test_result.xml'
}
def test_func_array = [:]
def test_results = [:]
test_func_array['Python_Tests'] = {run_job('Run_Python_Tests', test_results)}
test_func_array['JS_Tests'] = {run_job('Run_JS_Tests', test_results)}
test_func_array['Selenium_Tests'] = {run_job('Run_Selenium_Tests', test_results)}
parallel(test_func_array)
I am able to get the build number using the output.getNumber()
call when each job succeeds. However, when a job fails, build()
function call throws an exception so I cannot get the build number.
However, failed builds can still have build numbers and have archived artifacts. How do I get the build number of a failed build?