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!





Master:

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] { 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>[Pipeline] 
stage 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>[Pipeline] { 
(test-parallel) 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>[Pipeline] 
parallel 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>[Pipeline] { 
(Branch: DSWZ10001) 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>[Pipeline] { 
(Branch: DSWZ10022) 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>[Pipeline] 
build (Building tests » tmp_on_node) 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>Scheduling 
project: tests » tmp_on_node 
<http://dswz10000:8080/job/tests/job/tmp_on_node/>[Pipeline] build (Building 
tests » tmp_on_node) 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>Scheduling 
project: tests » tmp_on_node <http://dswz10000:8080/job/tests/job/tmp_on_node/>
Starting building: tests » tmp_on_node #78 
<http://dswz10000:8080/job/tests/job/tmp_on_node/78/>Starting building: tests » 
tmp_on_node #77 <http://dswz10000:8080/job/tests/job/tmp_on_node/77/>[Pipeline] 
}Failed in branch DSWZ10022[Pipeline] }Failed in branch DSWZ10001[Pipeline] // 
parallel[Pipeline] echo 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>Test failed 
with Error: hudson.AbortException: tests » tmp_on_node #78 completed with 
status FAILURE (propagate: false to ignore)[Pipeline] echo 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>*Runwrapper is 
null
[Pipeline] echo <http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>
**Runwrapper is null*[Pipeline] echo 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>[Pipeline] echo 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>[Pipeline] 
error 
<http://dswz10000:8080/job/tests/job/test_stefma_2/110/console#>[Pipeline] 
}[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of 
PipelineERROR: 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] { 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>[Pipeline] 
stage (hide 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>)[Pipeline] { 
(test-parallel) 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>[Pipeline] 
parallel 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>[Pipeline] { 
(Branch: DSWZ10001) 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>[Pipeline] { 
(Branch: DSWZ10022) 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>[Pipeline] 
build (Building tests » tmp_on_node) 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>Scheduling 
project: tests » tmp_on_node 
<http://dswz10000:8080/job/tests/job/tmp_on_node/>[Pipeline] build (Building 
tests » tmp_on_node) 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>Scheduling 
project: tests » tmp_on_node <http://dswz10000:8080/job/tests/job/tmp_on_node/>
Starting building: tests » tmp_on_node #80 
<http://dswz10000:8080/job/tests/job/tmp_on_node/80/>Starting building: tests » 
tmp_on_node #79 <http://dswz10000:8080/job/tests/job/tmp_on_node/79/>[Pipeline] 
}[Pipeline] }[Pipeline] // parallel[Pipeline] script 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>[Pipeline] { 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>[Pipeline] echo 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>Runwrapper 
exists[Pipeline] echo 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>Runwrapper 
exists[Pipeline] echo 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>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 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>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 
<http://dswz10000:8080/job/tests/job/test_stefma_2/111/console#>Test 
OK[Pipeline] }[Pipeline] // script[Pipeline] }[Pipeline] // stage[Pipeline] 
}[Pipeline] // node[Pipeline] End of PipelineFinished: SUCCESS





Is there any other way to get a nun-null runWrapper-Object from build job 
in case it fails?

Best regards,

Marco

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/0dfb3242-95e8-4d5f-9b5f-cadf078dfde8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to