Skip to content
Permalink
Newer
Older
100644 116 lines (93 sloc) 3.38 KB
1
// Licensed to the University Corporation for Advanced Internet Development,
2
// Inc. (UCAID) under one or more contributor license agreements. See the
3
// NOTICE file distributed with this work for additional information regarding
4
// copyright ownership. The UCAID licenses this file to You under the Apache
5
// License, Version 2.0 (the "License"); you may not use this file except in
6
// compliance with the License. You may obtain a copy of the License at
7
//
8
// http://www.apache.org/licenses/LICENSE-2.0
9
//
10
// Unless required by applicable law or agreed to in writing, software
11
//distributed under the License is distributed on an "AS IS" BASIS,
12
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
// See the License for the specific language governing permissions and
14
// limitations under the License.
15
//
16
node('docker') {
17
18
stage 'Checkout'
19
20
checkout scm
21
Oct 5, 2018
22
stage 'Acquire util files'
23
24
sh 'mkdir -p tmp && mkdir -p bin'
25
dir('tmp'){
26
git([ url: "https://github.internet2.edu/docker/util.git",
27
credentialsId: "jenkins-github-access-token" ])
28
sh 'rm -rf ../bin/*'
29
sh 'mv ./bin/* ../bin/.'
30
}
31
sh 'rm -rf tmp'
32
33
stage 'Setting build context'
34
35
def maintainer = maintainer()
Jun 23, 2020
36
def previous_maintainer = previous_maintainer()
37
def imagename = imagename()
38
def tag
39
40
// Tag images created on master branch with 'latest'
41
if(env.BRANCH_NAME == "master"){
42
tag = "latest"
43
}else{
44
tag = env.BRANCH_NAME
45
}
46
47
if(!imagename){
48
echo "You must define an imagename in common.bash"
49
currentBuild.result = 'FAILURE'
50
}
51
if(maintainer){
52
echo "Building ${imagename}:${tag} for ${maintainer}"
53
}
54
55
stage 'Build'
Oct 5, 2018
56
57
try{
58
sh 'bin/rebuild.sh &> debug'
59
} catch(error) {
60
def error_details = readFile('./debug');
61
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
62
sh "rm -f ./debug"
63
handleError(message)
64
}
Oct 5, 2018
65
66
stage 'Test'
67
68
try {
69
sh 'bin/test.sh 2>&1 | tee debug ; test ${PIPESTATUS[0]} -eq 0'
70
} catch (error) {
71
def error_details = readFile('./debug')
72
def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}"
73
sh "rm -f ./debug"
74
handleError(message)
75
}
76
77
stage 'Push'
78
Jun 23, 2020
79
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$previous_maintainer") {
80
def baseImg = docker.build("$maintainer/$imagename")
81
baseImg.push("$tag")
82
}
Jun 23, 2020
84
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$previous_maintainer") {
85
def altImg = docker.build("$previous_maintainer/$imagename")
86
altImg.push("$tag")
87
}
88
89
stage 'Notify'
Oct 5, 2018
90
91
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub"
92
93
}
94
95
def maintainer() {
96
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
97
matcher ? matcher[0][1] : 'i2incommon'
98
}
99
100
def previous_maintainer() {
101
def matcher = readFile('common.bash') =~ 'previous_maintainer="(.+)"'
102
matcher ? matcher[0][1] : 'tier'
103
}
104
105
def imagename() {
106
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
107
matcher ? matcher[0][1] : null
108
}
109
110
def handleError(String message){
111
echo "${message}"
112
currentBuild.setResult("FAILED")
113
slackSend color: 'danger', message: "${message} (<${env.BUILD_URL}|Open>)"
114
sh 'exit 1'
115
}
116
You can’t perform that action at this time.