I have a use case where I want to extract information from a Child job in the parent job.
This is my pipeline script:
pipeline {
agent any
stages {
stage('Validate Other Job') {
steps {
script {
echo "triggerring build"
def triggeredJob = build job: 'Pipeline1'
def logs = triggeredJob.rawBuild.getLog(100)
echo "Logs '$logs'"
}
}
}
}
}
Output: When ‘Pipeline1’ job status is: SUCCESS
It prints the logs
Issue: When ‘Pipeline1’ job status is: FAILURE or UNSTABLE
It throws error:
Build Pipeline1 #18 completed: FAILURE
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Pipieline1 #18 completed with status FAILURE (propagate: false to ignore)
org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: edf4f356-929c-4720-
a57f-b2bdef027f2c
Finished: FAILURE
My use case is to get the logs when Build fails/unstable and check that weather a particular string is available in the logs. If yes, then trigger a mail.
Child job is a dummy job:
pipeline {
agent any
stages {
stage('Hello') {
steps1 { // step1 for marking the build fail for testing
echo 'Hello World'
}
}
}
}