Skip to content
Permalink
Newer
Older
100644 74 lines (58 sloc) 1.65 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'
17
18
def maintainer = maintainer()
19
def imagename = imagename()
20
def tag = env.BRANCH_NAME
21
if(!imagename){
22
echo "You must define an imagename in common.bash"
23
currentBuild.result = 'FAILURE'
24
}
25
if(maintainer){
26
echo "Building ${maintainer}:${tag} for ${maintainer}"
27
}
Jim Van Fleet
Aug 24, 2016
28
29
stage 'Build'
30
try{
31
sh 'bin/build.sh &> debug'
32
} catch(error) {
33
def error_details = readFile('./debug');
34
def message = "BUILD ERROR: There was a problem building the Base Image. \n\n ${error_details}"
35
sh "rm -f ./debug"
36
handleError(message)
37
}
38
stage 'Start container'
39
40
sh 'bin/ci-run.sh'
41
Jim Van Fleet
Aug 24, 2016
42
stage 'Tests'
43
44
sh 'bin/test.sh'
45
// should build a finally construct here
46
stage 'Stop container'
47
48
sh 'bin/ci-stop.sh'
Jim Van Fleet
Aug 24, 2016
49
50
stage 'Push'
Jim Van Fleet
Aug 24, 2016
51
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
Jim Van Fleet
Aug 24, 2016
52
def baseImg = docker.build("$maintainer/$imagename")
53
baseImg.push("$tag")
54
}
55
56
57
}
58
59
def maintainer() {
60
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
61
matcher ? matcher[0][1] : 'tier'
62
}
63
64
def imagename() {
65
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
66
matcher ? matcher[0][1] : null
67
}
68
69
def handleError(String message){
70
echo "${message}"
71
currentBuild.setResult("FAILED")
72
slackSend color: 'danger', message: "${message}"
73
sh 'exit 1'
74
}
You can’t perform that action at this time.