Upstream Job:
pipeline {
agent any
stages {
stage('Hello') {
steps {
build job: 'test-app', parameters: [string(name: 'dummy', value: "")]
}
}
}
}
Downstream Job:
pipeline {
agent any
stages {
stage('Hello - downstream') {
steps {
try{
sh ''
}
catch(e){
emailext body: "Stage failed, Please check $BUILD_URL", subject: 'Build Failed', recipientProviders: [buildUser()]
}
}
}
}
if downstream job fails, I want to send email to the user who triggered it's upstream job. [buildUser()] is giving errors.
First, you need to find out which job triggered the downstream job.
Then it can be found out who triggered the upstream job
From the
upstreamJobCauseit is possible to retrieveUserobject and then the email address of that userYou can put this code into your
catchblock. Note that this code will only work for your use case, otherwise error handling is necessary (e.g. if upstream job gets time-triggered the code will not work).Mailer UserProperty
Model Run
Model User