Permalink
Jul 5, 2016
Aug 30, 2016
Aug 30, 2016
Jul 5, 2016
Aug 30, 2016
Aug 30, 2016
Aug 30, 2016
Jul 5, 2016
Aug 30, 2016
Aug 4, 2016
Aug 30, 2016
Newer
100644
82 lines (67 sloc)
2.08 KB

1
node {
2
stage 'Checkout'
3
4
checkout scm

9
dir('tmp'){
10
git([ url: "https://github.internet2.edu/docker/util.git",
11
credentialsId: "jenkins-github-access-token" ])

15
stage 'Setting build context'
16
17
def maintainer = maintainer()
18
def imagename = imagename()
19
def tag
20
21
// Tag images created on master branch with 'latest'
22
if(env.BRANCH_NAME == "master"){
23
tag = "latest"
24
}else{
25
tag = env.BRANCH_NAME
26
}
27
28
if(!imagename){
29
echo "You must define an imagename in common.bash"
30
currentBuild.result = 'FAILURE'
31
}
32
if(maintainer){
33
echo "Building ${maintainer}:${tag} for ${maintainer}"
34
}

35

42
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"

49
try{
50
sh 'bin/test.sh &> debug'
51
} catch(error) {
52
def error_details = readFile('./debug');
53
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
54
sh "rm -f ./debug"
55
handleError(message)
56
}

60
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
61
def baseImg = docker.build("$maintainer/$imagename")
62
baseImg.push("$tag")

65

66
def maintainer() {
67
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
68
matcher ? matcher[0][1] : 'tier'
69
}
70
71
def imagename() {
72
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
73
matcher ? matcher[0][1] : null
74
}
75

76
def handleError(String message){
77
echo "${message}"
78
currentBuild.setResult("FAILED")
79
slackSend color: 'danger', message: "${message}"

80
//step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chris.bynum@levvel.io', sendToIndividuals: true])