Skip to content
Permalink
Newer
Older
100644 82 lines (64 sloc) 1.8 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
}
Jim Van Fleet
Aug 24, 2016
16
stage 'Environment'
Jim Van Fleet
Aug 24, 2016
18
def maintainer = maintainer()
19
def imagename = imagename()
20
def tag = env.BRANCH_NAME
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 ${maintainer}:${tag} for ${maintainer}"
35
}
Jim Van Fleet
Aug 24, 2016
36
37
stage 'Build'
38
try{
39
sh 'bin/build.sh &> debug'
40
} catch(error) {
41
def error_details = readFile('./debug');
42
def message = "BUILD ERROR: There was a problem building the Base Image. \n\n ${error_details}"
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
sh 'bin/test.sh'
53
// should build a finally construct here
54
stage 'Stop container'
55
56
sh 'bin/ci-stop.sh'
Jim Van Fleet
Aug 24, 2016
57
58
stage 'Push'
Jim Van Fleet
Aug 24, 2016
59
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
Jim Van Fleet
Aug 24, 2016
60
def baseImg = docker.build("$maintainer/$imagename")
61
baseImg.push("$tag")
62
}
63
64
65
}
66
67
def maintainer() {
68
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
69
matcher ? matcher[0][1] : 'tier'
70
}
71
72
def imagename() {
73
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
74
matcher ? matcher[0][1] : null
75
}
76
77
def handleError(String message){
78
echo "${message}"
79
currentBuild.setResult("FAILED")
80
slackSend color: 'danger', message: "${message}"
81
sh 'exit 1'
82
}
You can’t perform that action at this time.