'How to get child job logs in parent job on child job failure?

I want to get child job logs in parent job irrespective of if child job passes or fails. Following code returns child jobs logs in parent job only when child job passes -

pipeline {
    agent any
    stages {
      stage('Hello') {

        steps {
            echo 'Hello World'
            echo 'In parent job'
            script {
                def result = build job: 'ChildJob', parameters: []
                 println result.getRawBuild().getLog()
            }
        }     
      }
    }  
}

Is there any way where on failure I can get child job logs in parent job?



Solution 1:[1]

from https://jenkins.io/doc/pipeline/steps/pipeline-build-step/

propagate (optional) If set, then if the downstream build is anything but successful (blue ball), this step fails. If disabled, then this step succeeds even if the downstream build is unstable, failed, etc.; use the result property of the return value as needed.

This should exactly answer your question

Solution 2:[2]

A bit late to the game but I managed this with propagate: false like this:

script {
  def run = build(
    job: "job name here",
    propagate: false
  )
                
  println(run.rawBuild.getLog())

  currentBuild.result = run.getResult()
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Holleoman
Solution 2 TheContstruct