package chef
Throwable exception = null
boolean validate() {
validated = false
try {
sh 'validate'
validated = true
} catch (Throwable ex) {
exception = ex
}
return (boolean)validated
}
boolean publish() {
published = false
try {
sh 'publish'
published = true
} catch (Throwable ex) {
exception = ex
}
return (boolean)published
}
def emailResults(Map args) {
if (exception != null) {
exceptionDetails = """<p>The job failed with the following error:</p>
<pre style=\"padding:7px;background-color:#E0E0E0;\">${exception.toString()}
${exception.getStackTrace().join('\n')}</pre>"""
}
subject: "Validation Job ${env['JOB_NAME']} ${subject}",
mimeType: 'text/html',
body: """<html><body>
<p>The alidation job <strong>${env['JOB_NAME']}</strong> ${message}</p>
<p>This job run is viewable on Jenkins at: </p>
<p style=\"padding:10px\"><a href=\"${env['BUILD_URL']}\">${env['BUILD_URL']}</a></p>
${exceptionDetails}
<body></html>"""
}
def done() {
if (exception != null) {
echo """The job failed with the following error:
${exception.toString()}
${exception.getStackTrace().join('\n')}
"""
throw exception
}
}