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