Hello, Jenkins geeks.
Once upon a time, users asked to show downstream job’s build log if that downstream job failed.
This is easy!
def downstreamResult = build(
job: env.JOB_NAME_TO_TRIGGER,
parameters: [
string(name: "parameter", value: "value"),
],
propagate: false,
wait: true
)
def downstreamLog = Jenkins.getInstance().getItemByFullName(env.JOB_NAME_TO_TRIGGER).getBuildByNumber(downstreamResult.getNumber()).log
println downstreamLog
currentBuild.result = downstreamResult.getResult()
if (!"SUCCESS".equals(currentBuild.result)) {
error("Downstream job failed. Check log output.")
}
Parameter wait
is mandatory!
Happy Scripting!