Skip to content
Permalink
Newer
Older
100644 130 lines (126 sloc) 4.31 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'
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
}
33
stage ('Build') {
34
steps {
35
script {
36
try {
37
sh './download-midpoint &> debug'
38
sh 'bin/rebuild.sh &>> debug'
39
sh 'echo Build output ; cat debug'
40
} catch (error) {
41
def error_details = readFile('./debug')
42
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
43
sh "rm -f ./debug"
44
handleError(message)
45
}
46
}
47
}
48
}
49
stage ('Test') {
50
steps {
51
script {
52
try {
53
sh 'bin/test.sh &> debug'
54
sh '(cd demo/simple ; bats tests ) &>> debug'
Sep 27, 2018
55
sh 'echo Test output ; cat debug'
56
} catch (error) {
57
def error_details = readFile('./debug')
58
def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}"
59
sh "rm -f ./debug"
60
handleError(message)
61
}
62
}
63
}
64
}
66
stage ('Test2') {
67
steps {
68
script {
69
try {
70
try {
71
sh 'docker pull tier/mariadb:mariadb10' // temporary
72
sh 'env NOCOLOR=true ./test.sh'
73
} finally {
74
sh './cleanup.sh'
75
}
76
} catch (error) {
77
def error_details = readFile('./debug')
78
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
79
sh "rm -f ./debug"
80
handleError(message)
81
}
82
}
83
}
84
}
86
stage ('Push') {
87
steps {
88
script {
89
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
90
def baseImg = docker.build("$maintainer/$imagename")
91
baseImg.push("$tag")
92
}
93
}
94
}
95
}
96
stage ('Notify') {
97
steps {
98
echo "$maintainer"
99
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub"
100
}
101
}
102
}
103
post {
104
always {
105
echo 'Done Building.'
106
}
107
failure {
108
// slackSend color: 'good', message: "Build failed"
109
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename}:${tag}.")
110
}
111
}
112
}
113
114
115
def maintain() {
116
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
117
matcher ? matcher[0][1] : 'tier'
118
}
119
120
def imagename() {
121
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
122
matcher ? matcher[0][1] : null
123
}
124
125
def handleError(String message) {
126
echo "${message}"
127
currentBuild.setResult("FAILED")
128
slackSend color: 'danger', message: "${message}"
129
sh 'exit 1'
You can’t perform that action at this time.