Skip to content
Permalink
Newer
Older
100644 116 lines (111 sloc) 4.53 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") {
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/.'
30
// Build and test scripts expect that 'tag' is present in common.bash. This is necessary for both Jenkins and standalone testing.
31
// We don't care if there are more 'tag' assignments there. The latest one wins.
Oct 5, 2018
32
sh "echo >> common.bash ; echo \"tag=\\\"${tag}\\\"\" >> common.bash ; echo common.bash ; cat common.bash"
33
}
34
}
36
stage ('Build') {
37
steps {
38
script {
39
try {
40
// using custom ./build.sh instead of bin/rebuild.sh because the bin/ version does not support building specific tag yet
41
sh './build.sh -r 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
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
}
50
}
51
stage ('Test') {
52
steps {
53
script {
54
try {
55
sh 'echo Docker containers before root tests ; docker ps -a' // temporary
56
sh 'bin/test.sh 2>&1 | tee debug ; test ${PIPESTATUS[0]} -eq 0'
57
sh 'echo Docker containers before compositions tests ; docker ps -a' // temporary
58
59
sh '(cd demo/simple ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
60
sh '(cd demo/shibboleth ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
61
sh '(cd demo/postgresql ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
62
sh '(cd demo/complex ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
63
} catch (error) {
64
def error_details = readFile('./debug')
65
def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}"
66
sh "rm -f ./debug"
67
handleError(message)
68
}
69
}
70
}
71
}
73
steps {
74
script {
75
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
76
def baseImg = docker.build("$maintainer/$imagename")
77
baseImg.push("$tag")
78
}
79
}
80
}
81
}
82
stage ('Notify') {
83
steps {
84
echo "$maintainer"
85
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub"
86
}
87
}
88
}
89
post {
90
always {
91
echo 'Done Building.'
92
}
93
failure {
94
// slackSend color: 'good', message: "Build failed"
95
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename}:${tag}.")
96
}
97
}
98
}
99
100
101
def maintain() {
102
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
103
matcher ? matcher[0][1] : 'tier'
104
}
105
106
def imagename() {
107
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
108
matcher ? matcher[0][1] : null
109
}
110
111
def handleError(String message) {
112
echo "${message}"
113
currentBuild.setResult("FAILED")
114
slackSend color: 'danger', message: "${message}"
115
sh 'exit 1'
You can’t perform that action at this time.