Skip to content
Permalink
Newer
Older
100644 91 lines (72 sloc) 2.14 KB
1
node('docker') {
Jim Van Fleet
Aug 24, 2016
2
3
stage 'Checkout'
4
5
checkout scm
6
7
stage 'Acquire util'
8
9
sh 'mkdir -p tmp'
10
dir('tmp'){
Jim Van Fleet
Aug 24, 2016
11
git([ url: "https://github.internet2.edu/docker/util.git",
12
credentialsId: "jenkins-github-access-token" ])
13
sh 'ls'
14
sh 'mv bin/* ../bin/.'
Jim Van Fleet
Aug 24, 2016
15
}
16
stage 'Setting build context'
17
Jim Van Fleet
Aug 24, 2016
18
def maintainer = maintainer()
19
def imagename = imagename()
20
def tag
21
22
// Tag images created on master branch with 'latest'
23
if(env.BRANCH_NAME == "master"){
24
tag = "latest"
25
}else{
26
tag = env.BRANCH_NAME
27
}
28
29
if(!imagename){
Jim Van Fleet
Aug 24, 2016
30
echo "You must define an imagename in common.bash"
31
currentBuild.result = 'FAILURE'
32
}
33
if(maintainer){
34
echo "Building ${imagename}:${tag} for ${maintainer}"
35
}
Jim Van Fleet
Aug 24, 2016
36
37
stage 'Build'
38
try{
39
sh 'bin/rebuild.sh &> debug'
Jim Van Fleet
Aug 24, 2016
40
} catch(error) {
41
def error_details = readFile('./debug');
42
def message = "BUILD ERROR: There was a problem building the shibboleth-sp mage. \n\n ${error_details}"
Jim Van Fleet
Aug 24, 2016
43
sh "rm -f ./debug"
44
handleError(message)
45
}
46
stage 'Start container'
47
48
sh 'bin/ci-run.sh'
49
Jim Van Fleet
Aug 24, 2016
50
stage 'Tests'
51
52
try{
53
sh 'bin/test.sh &> debug'
54
} catch(error) {
55
def error_details = readFile('./debug');
56
def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}"
57
sh "rm -f ./debug"
58
handleError(message)
59
}
60
61
stage 'Stop container'
62
63
sh 'bin/ci-stop.sh'
Jim Van Fleet
Aug 24, 2016
64
65
stage 'Push'
Jim Van Fleet
Aug 24, 2016
66
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
Jim Van Fleet
Aug 24, 2016
67
def baseImg = docker.build("$maintainer/$imagename")
68
baseImg.push("$tag")
69
}
70
71
stage 'Notify'
72
73
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub"
Jim Van Fleet
Aug 24, 2016
74
}
75
76
def maintainer() {
77
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
78
matcher ? matcher[0][1] : 'tier'
79
}
80
81
def imagename() {
82
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
83
matcher ? matcher[0][1] : null
84
}
85
86
def handleError(String message){
87
echo "${message}"
88
currentBuild.setResult("FAILED")
89
slackSend color: 'danger', message: "${message}"
90
sh 'exit 1'
91
}
You can’t perform that action at this time.