Skip to content

Commit

Permalink
Tests require a running container. Also testing cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Van Fleet committed Jul 13, 2017
1 parent f465ed4 commit e37ce66
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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"
Expand All @@ -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)
}
}

0 comments on commit e37ce66

Please sign in to comment.