I want to send email notification when any job gets done. Please let me know how can we propagate.
All the above answers are about plug-in and its usage but not how to use it in pipeline execution. Assuming smtp server is configured in jenkins and https://plugins.jenkins.io/email-ext/ plug-in is installed , we can write or use the plug-in ij the below format.
def csproj_path = 'dotnetcore_sample.csproj'
pipeline {
agent{
node {
label 'dotnet-31'
}
}
stages {
stage ('build locally'){
steps{
sh "dotnet build ${csproj_path}"
}
}
stage ('Prompt check'){
steps {
mail to: 'mymail@gmail.com',
cc : 'ccedpeople@gamil.com'
subject: "INPUT: Build ${env.JOB_NAME}",
body: "Awaiting for your input ${env.JOB_NAME} build no: ${env.BUILD_NUMBER} .Click below to promote to production\n${env.JENKINS_URL}job/${env.JOB_NAME}\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}"
timeout(time: 60, unit: 'MINUTES'){
input message: "Promote to Production?", ok: "Promote"
}
}
}
}
post {
failure {
mail to: 'mymail@gmail.com',
cc : 'ccedpeople@gamil.com'
subject: "FAILED: Build ${env.JOB_NAME}",
body: "Build failed ${env.JOB_NAME} build no: ${env.BUILD_NUMBER}.\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}"
}
success{
mail to: 'mymail@gmail.com',
cc : 'ccedpeople@gamil.com'
subject: "SUCCESSFUL: Build ${env.JOB_NAME}",
body: "Build Successful ${env.JOB_NAME} build no: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}"
}
aborted{
mail to: 'mymail@gmail.com',
cc : 'ccedpeople@gamil.com'
subject: "ABORTED: Build ${env.JOB_NAME}",
body: "Build was aborted ${env.JOB_NAME} build no: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}"
}
}
}
The above declarative pipeline consists of below features