Skip to content
Permalink
Newer
Older
100644 82 lines (67 sloc) 2.08 KB
1
node {
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-bigfleet') {
61
def baseImg = docker.build('bigfleet/centos7base')
62
baseImg.push('latest')
63
}
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])
81
sh 'exit 1'
82
}
You can’t perform that action at this time.