pipeline { agent label:'docker'
stages { stage('maven-build') { steps { sh 'mvn clean install' } } }
post { always { archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml']) }
changed { sendEmail(config, 'CHANGED') }
failure { sendEmail(config, 'FAILURE') } } }
#!/usr/bin/env groovydef config = [emailRecipients: 'email@com', attachLog: false]
def buildStateHasChanged = false;
pipeline { agent label:'docker'
stages { stage('maven-build') { steps { sh 'mvn clean install' } } }
post { always { archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml']) }
success { script { if (buildStateHasChanged == true) { echo "Emailing for success because build state has changed..." sendEmail(config, 'SUCCESS') } } } changed { echo "Build state has changed..." script { buildStateHasChanged = true } }
failure { sendEmail(config, 'FAILURE') } } }
def sendEmail(config, status) { // We need to do this because the template uses it and it won't be set properly in pipeline currentBuild.result = status
def subject = config.subject ? config.subject : "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${status}!" def content = '${SCRIPT,template="groovy-html-tim.template"}' def attachLog = config.attachLog != null ? config.attachLog : (status != "SUCCESS")
def to = [] to << emailextrecipients([[$class: 'RequesterRecipientProvider']])
if (config.emailRecipients != null) { to << config.emailRecipients }
if (status != "SUCCESS") { to << emailextrecipients([[$class: 'CulpritsRecipientProvider']]) }
to = to.join(',')
emailext(body: content, mimeType:'text/html', replyTo: '$DEFAULT_REPLYTO', subject: subject, to: to, attachLog: attachLog)}