Skip to content
Permalink
Newer
Older
100644 67 lines (53 sloc) 1.6 KB
Jim Van Fleet
Aug 24, 2016
1
node {
2
3
stage 'Checkout'
4
5
checkout scm
6
7
stage 'Acquire util'
8
9
sh 'mkdir -p bin'
10
dir('bin'){
11
git([ url: "https://github.internet2.edu/docker/util.git",
12
credentialsId: "jenkins-github-access-token" ])
13
sh 'ls'
14
sh 'mv bin/* .'
15
}
16
17
stage 'Build'
18
try{
19
def maintainer = maintainer()
20
def imagename = imagename()
21
def tag = env.BRANCH_NAME
22
if(!imagename){
23
echo "You must define an imagename in common.bash"
24
currentBuild.result = 'FAILURE'
25
}
26
if(maintainer){
27
echo "Building ${maintainer}:${tag} for ${maintainer}"
28
}
29
30
sh 'bin/build.sh &> debug'
31
} catch(error) {
32
def error_details = readFile('./debug');
33
def message = "BUILD ERROR: There was a problem building the Base Image. \n\n ${error_details}"
34
sh "rm -f ./debug"
35
handleError(message)
36
}
37
stage 'Tests'
38
39
sh 'bin/test.sh'
40
41
stage 'Push'
42
43
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
44
def baseImg = docker.build("$maintainer/$imagename")
45
baseImg.push("$tag")
46
}
47
48
49
}
50
51
def maintainer() {
52
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
53
matcher ? matcher[0][1] : 'tier'
54
}
55
56
def imagename() {
57
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
58
matcher ? matcher[0][1] : null
59
}
60
61
def handleError(String message){
62
echo "${message}"
63
currentBuild.setResult("FAILED")
64
slackSend color: 'danger', message: "${message}"
65
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "$email-error-id", sendToIndividuals: true])
66
sh 'exit 1'
67
}
You can’t perform that action at this time.