From e37ce6602eae093f4471b6b1a342c047fd8eaebb Mon Sep 17 00:00:00 2001 From: Jim Van Fleet Date: Thu, 13 Jul 2017 16:16:55 -0400 Subject: [PATCH] Tests require a running container. Also testing cleanup --- Jenkinsfile | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 87f1ee7..b4b1413 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,7 +42,7 @@ node('docker') { def error_details = readFile('./debug'); def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}" sh "rm -f ./debug" - handleError(message) + handleError(message, tag) } stage 'Start container' @@ -57,7 +57,7 @@ node('docker') { def error_details = readFile('./debug'); def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}" sh "rm -f ./debug" - handleError(message) + handleError(message, tag) } stage 'Stop container' @@ -71,6 +71,10 @@ node('docker') { baseImg.push("$tag") } + stage 'Clean Up' + + cleanup(tag) + stage 'Notify' slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub" @@ -87,10 +91,24 @@ def imagename() { matcher ? matcher[0][1] : null } -def handleError(String message){ +def handleError(String message, String tag, Boolean doCleanup = true){ echo "${message}" currentBuild.setResult("FAILED") slackSend color: 'danger', message: "${message}" //step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chris.bynum@levvel.io', sendToIndividuals: true]) + if (doCleanup) { + cleanup(tag) + } sh 'exit 1' +} + +def cleanup(String tag) { + try{ + sh 'bin/destroy.sh &> debug' + } catch(error) { + def error_details = readFile('./debug'); + def message = "BUILD ERROR: There was a problem cleaning up ${imagename}:${tag}. \n\n ${error_details}" + sh "rm -f ./debug" + handleError(message, tag, false) + } } \ No newline at end of file