I have a pipeline triggering multiple downstream jobs. For each of those jobs I would at least like to get the log-output. Even in case the downstream-build has failed!
def getBuildLog(Object runWrapper) {
if (runWrapper != null) {
echo "Runwrapper exists"
return runWrapper.getRawBuild().getLog(100).join('\n')
}
echo "Runwrapper is null"
return ""
}
node ('master')
{
stage('test-parallel') {
def jobBuild_1 = null
def jobBuild_2 = null
try {
parallel(
DSWZ10001: {
jobBuild_1 = build job: 'tmp_on_node', parameters: [[$class: 'LabelParameterValue', name: 'node_label', label: 'DSWZ10001']]
},
DSWZ10022: {
jobBuild_2 = build job: 'tmp_on_node', parameters: [[$class: 'LabelParameterValue', name: 'node_label', label: 'DSWZ10022']]
}
)
} catch (Exception e)
{
// In that case runwrapper is null
echo 'Test failed with Error: ' + e.toString()
def log_1 = getBuildLog(jobBuild_1)
def log_2 = getBuildLog(jobBuild_2)
print log_1
print log_2
error 'Test has failed'
}
script {
def log_1 = getBuildLog(jobBuild_1)
def log_2 = getBuildLog(jobBuild_2)
print log_1
print log_2
print 'Test OK'
}
}
}
tmp_on_node:
node (env.node_label) {
stage('[DetermineVersion]')
{
println("stdout ################ 1 ####################")
println("stdout ################ 2 ####################")
println("stdout ################ 3 ####################")
println("stdout ################ 4 ####################")
println("stdout ################ 5 ####################")
error "Failed for testing"
}
}
If tmp_on_node fails jobBuild_1 and jobBuild_2 are null. Thus, I cannot get the build-log or any other information from the downstreams:
[Pipeline] {
[Pipeline] stage
[Pipeline] { (test-parallel)
[Pipeline] parallel
[Pipeline] { (Branch: DSWZ10001)
[Pipeline] { (Branch: DSWZ10022)
[Pipeline] build (Building tests » tmp_on_node)
Scheduling project: tests » tmp_on_node
[Pipeline] build (Building tests » tmp_on_node)
Scheduling project: tests » tmp_on_node
Starting building: tests » tmp_on_node #78
Starting building: tests » tmp_on_node #77
[Pipeline] }
Failed in branch DSWZ10022
[Pipeline] }
Failed in branch DSWZ10001
[Pipeline] // parallel
[Pipeline] echo
Test failed with Error: hudson.AbortException: tests » tmp_on_node #78 completed with status FAILURE (propagate: false to ignore)
[Pipeline] echo
Runwrapper is null
[Pipeline] echo
Runwrapper is null
[Pipeline] echo
[Pipeline] echo
[Pipeline] error
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Test has failed
Finished: FAILURE
If I comment out the error in tmp_on_node, both builds succeed as expected giving non-null values for jobBuild-variables:
[Pipeline] {
[Pipeline] stage (hide)
[Pipeline] { (test-parallel)
[Pipeline] parallel
[Pipeline] { (Branch: DSWZ10001)
[Pipeline] { (Branch: DSWZ10022)
[Pipeline] build (Building tests » tmp_on_node)
Scheduling project: tests » tmp_on_node
[Pipeline] build (Building tests » tmp_on_node)
Scheduling project: tests » tmp_on_node
Starting building: tests » tmp_on_node #80
Starting building: tests » tmp_on_node #79
[Pipeline] }
[Pipeline] }
[Pipeline] // parallel
[Pipeline] script
[Pipeline] {
[Pipeline] echo
Runwrapper exists
[Pipeline] echo
Runwrapper exists
[Pipeline] echo
Started by upstream project "tests/test_stefma_2" build number 111
originally caused by:
Started by user Steffan Marco
Running in Durability level: MAX_SURVIVABILITY
...[Pipeline] Start of Pipeline
[Pipeline] node
Running on DSWZ10001 in C:\appl\Jenkins\workspace\tests\tmp_on_node
[Pipeline] {
[Pipeline] stage
[Pipeline] { ([DetermineVersion])
[Pipeline] echo
stdout ################ 1 ####################
[Pipeline] echo
stdout ################ 2 ####################
[Pipeline] echo
stdout ################ 3 ####################
[Pipeline] echo
stdout ################ 4 ####################
[Pipeline] echo
stdout ################ 5 ####################
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
[Pipeline] echo
Started by upstream project "tests/test_stefma_2" build number 111
originally caused by:
Started by user Steffan Marco
Running in Durability level: MAX_SURVIVABILITY
...
[Pipeline] Start of Pipeline
[Pipeline] node
Running on DSWZ10022 in C:\appl\Jenkins\workspace\tests\tmp_on_node
[Pipeline] {
[Pipeline] stage
[Pipeline] { ([DetermineVersion])
[Pipeline] echo
stdout ################ 1 ####################
[Pipeline] echo
stdout ################ 2 ####################
[Pipeline] echo
stdout ################ 3 ####################
[Pipeline] echo
stdout ################ 4 ####################
[Pipeline] echo
stdout ################ 5 ####################
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
[Pipeline] echo
Test OK
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Is there any other way to get a nun-null runWrapper-Object from build job in case it fails?
Best regards,
Marco