Skip to content
Permalink
Newer
Older
100644 138 lines (134 sloc) 4.63 KB
1
pipeline {
2
agent any
3
environment {
4
maintainer = "t"
5
imagename = 'm'
6
tag = 'l'
7
}
8
stages {
9
stage('Setting build context') {
10
steps {
11
script {
12
maintainer = maintain()
13
imagename = imagename()
14
if(env.BRANCH_NAME == "master" || env.BRANCH_NAME == "bats") { // temporary
15
tag = "latest"
16
} else {
17
tag = env.BRANCH_NAME
18
}
19
if(!imagename){
20
echo "You must define imagename in common.bash"
21
currentBuild.result = 'FAILURE'
22
}
23
sh 'mkdir -p bin'
24
sh 'mkdir -p tmp'
25
dir('tmp') {
26
git([ url: "https://github.internet2.edu/docker/util.git", credentialsId: "jenkins-github-access-token" ])
27
sh 'ls'
28
sh 'mv bin/* ../bin/.'
29
}
30
}
31
}
32
}
33
stage ('Clean') {
34
steps {
35
script {
36
try {
37
sh 'bin/destroy.sh >> debug'
38
} catch (error) {
39
def error_details = readFile('./debug');
40
def message = "BUILD ERROR: There was a problem building the Base Image. \n\n ${error_details}"
41
sh "rm -f ./debug"
42
handleError(message)
43
}
44
}
45
}
46
}
47
stage ('Build') {
48
steps {
49
script {
50
try {
51
sh '(set -e ; cd midpoint ; ./download-midpoint ; ../bin/build.sh) &> debug'
52
} catch (error) {
53
def error_details = readFile('./debug')
54
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
55
sh "rm -f ./debug"
56
handleError(message)
57
}
58
}
59
}
60
}
61
stage ('Test') {
62
steps {
63
script {
64
try {
65
sh 'bats midpoint/tests &> debug'
66
} catch (error) {
67
def error_details = readFile('./debug')
68
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
69
sh "rm -f ./debug"
70
handleError(message)
71
}
72
}
73
}
74
}
75
stage ('Test2') {
76
steps {
77
script {
78
try {
79
try {
80
sh 'docker pull tier/mariadb:mariadb10' // temporary
81
sh 'env NOCOLOR=true ./test.sh'
82
} finally {
83
sh './cleanup.sh'
84
}
85
} catch (error) {
86
def error_details = readFile('./debug')
87
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
88
sh "rm -f ./debug"
89
handleError(message)
90
}
91
}
92
}
93
}
94
stage ('Push') {
95
steps {
96
script {
97
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
98
def baseImg = docker.build("$maintainer/$imagename")
99
baseImg.push("$tag")
100
}
101
}
102
}
103
}
104
stage ('Notify') {
105
steps {
106
echo "$maintainer"
107
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub"
108
}
109
}
110
}
111
post {
112
always {
113
echo 'Done Building.'
114
}
115
failure {
116
// slackSend color: 'good', message: "Build failed"
117
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename}:${tag}.")
118
}
119
}
120
}
121
122
123
def maintain() {
124
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
125
matcher ? matcher[0][1] : 'tier'
126
}
127
128
def imagename() {
129
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
130
matcher ? matcher[0][1] : null
131
}
132
133
def handleError(String message) {
134
echo "${message}"
135
currentBuild.setResult("FAILED")
136
slackSend color: 'danger', message: "${message}"
137
sh 'exit 1'
You can’t perform that action at this time.