Skip to content
Permalink
Newer
Older
100644 86 lines (69 sloc) 2.2 KB
1
node('docker') {
2
stage 'Checkout'
3
4
checkout scm
Jim Van Fleet
Aug 30, 2016
5
6
stage 'Acquire util'
7
Jim Van Fleet
Aug 30, 2016
8
sh 'mkdir -p tmp && mkdir -p bin'
Jim Van Fleet
Aug 30, 2016
9
dir('tmp'){
10
git([ url: "https://github.internet2.edu/docker/util.git",
11
credentialsId: "jenkins-github-access-token" ])
Jim Van Fleet
Aug 30, 2016
12
sh 'mv ./bin/* ../bin/.'
Jim Van Fleet
Aug 30, 2016
13
}
14
sh 'rm -rf tmp'
Jim Van Fleet
Aug 30, 2016
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
}
36
stage 'BUILD: Base'
37
38
try{
Jim Van Fleet
Aug 30, 2016
39
sh 'bin/build.sh &> debug'
40
} catch(error) {
41
def error_details = readFile('./debug');
Jim Van Fleet
Aug 30, 2016
42
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
43
sh "rm -f ./debug"
44
handleError(message)
45
}
46
47
stage 'TEST: Base'
48
Jim Van Fleet
Aug 30, 2016
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
}
57
58
stage 'SHIP: Base'
59
60
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
61
def baseImg = docker.build("$maintainer/$imagename")
62
baseImg.push("$tag")
63
}
Jim Van Fleet
Aug 30, 2016
64
65
stage 'Notify'
66
Jim Van Fleet
Aug 30, 2016
67
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub"
70
def maintainer() {
71
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
72
matcher ? matcher[0][1] : 'tier'
73
}
74
75
def imagename() {
76
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
77
matcher ? matcher[0][1] : null
78
}
79
80
def handleError(String message){
81
echo "${message}"
82
currentBuild.setResult("FAILED")
83
slackSend color: 'danger', message: "${message}"
84
//step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chris.bynum@levvel.io', sendToIndividuals: true])
85
sh 'exit 1'
86
}
You can’t perform that action at this time.