From b036068443a8c6ac3d3cd4b2aeaa85070aad7a7f Mon Sep 17 00:00:00 2001 From: Jim Van Fleet Date: Fri, 12 Aug 2016 12:22:53 -0400 Subject: [PATCH] Introducing notifications to build --- Jenkinsfile | 20 ++++++++++++++++++-- bin/ci-run.sh | 2 +- bin/ci-stop.sh | 3 +-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 92b3cad..9c5c080 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,11 +27,19 @@ node('docker') { echo "Building ${maintainer}:${tag} for ${maintainer}" } - sh 'bin/rebuild.sh' + try{ + // Build Base Image + sh 'bin/rebuild.sh &> debug' + } catch(error) { + def error_details = readFile('./debug'); + def message = "BUILD ERROR: There was a problem building ${imagename}. \n\n ${error_details}" + sh "rm -f ./debug" + handleError(message) + } stage 'Start container' - sh 'bin/ci-run.sh && sleep 60' + sh 'bin/ci-run.sh' stage 'Tests' @@ -59,4 +67,12 @@ def maintainer() { def imagename() { def matcher = readFile('common.bash') =~ 'imagename="(.+)"' matcher ? matcher[0][1] : null +} + +def handleError(String message){ + echo "${message}" + currentBuild.setResult("FAILED") + slackSend color: 'danger', message: "${message}" + step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chris.bynum@levvel.io', sendToIndividuals: true]) + sh 'exit 1' } \ No newline at end of file diff --git a/bin/ci-run.sh b/bin/ci-run.sh index 70761f0..80b6c0d 100755 --- a/bin/ci-run.sh +++ b/bin/ci-run.sh @@ -3,4 +3,4 @@ # This file will run a container in the background source common.bash . -docker run -d --name=$imagename -p 80:80 -p 443:443 $maintainer/$imagename \ No newline at end of file +docker run -d --name=$imagename -p 80:80 -p 443:443 $maintainer/$imagename diff --git a/bin/ci-stop.sh b/bin/ci-stop.sh index 2ac6a32..416db9e 100755 --- a/bin/ci-stop.sh +++ b/bin/ci-stop.sh @@ -5,5 +5,4 @@ source common.bash . echo "Cleaning up Docker image($maintainer/$imagename)" docker stop $imagename >> /dev/null -docker rm $imagename -exit 0 \ No newline at end of file +docker rm $imagename \ No newline at end of file