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