Skip to content
Permalink
Newer
Older
100644 119 lines (114 sloc) 4.49 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
sh "echo \"tag=\\\"${tag}\\\"\" > tag.bash ; chmod a+x tag.bash ; echo tag.bash ; cat tag.bash'
31
}
32
}
34
stage ('Build') {
35
steps {
36
script {
37
try {
38
if (env.BRANCH_NAME == "master") {
39
toDownload = "3.9-SNAPSHOT"
40
} else {
41
toDownload = env.BRANCH_NAME
42
}
43
sh "./download-midpoint ${toDownload} 2>&1 | tee -a debug ; test \${PIPESTATUS[0]} -eq 0"
44
sh './jenkins-rebuild.sh 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' // temporary
45
} catch (error) {
46
def error_details = readFile('./debug')
47
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
48
sh "rm -f ./debug"
49
handleError(message)
50
}
51
}
52
}
53
}
54
stage ('Test') {
55
steps {
56
script {
57
try {
58
sh 'echo Docker containers before root tests ; docker ps -a' // temporary
59
sh 'bin/test.sh 2>&1 | tee debug ; test ${PIPESTATUS[0]} -eq 0'
60
sh 'echo Docker containers before compositions tests ; docker ps -a' // temporary
61
62
sh '(cd demo/simple ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
63
sh '(cd demo/shibboleth ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
64
sh '(cd demo/postgresql ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
65
sh '(cd demo/complex ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
66
} catch (error) {
67
def error_details = readFile('./debug')
68
def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}"
69
sh "rm -f ./debug"
70
handleError(message)
71
}
72
}
73
}
74
}
76
steps {
77
script {
78
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
79
def baseImg = docker.build("$maintainer/$imagename")
80
baseImg.push("$tag")
81
}
82
}
83
}
84
}
85
stage ('Notify') {
86
steps {
87
echo "$maintainer"
88
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub"
89
}
90
}
91
}
92
post {
93
always {
94
echo 'Done Building.'
95
}
96
failure {
97
// slackSend color: 'good', message: "Build failed"
98
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename}:${tag}.")
99
}
100
}
101
}
102
103
104
def maintain() {
105
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
106
matcher ? matcher[0][1] : 'tier'
107
}
108
109
def imagename() {
110
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
111
matcher ? matcher[0][1] : null
112
}
113
114
def handleError(String message) {
115
echo "${message}"
116
currentBuild.setResult("FAILED")
117
slackSend color: 'danger', message: "${message}"
118
sh 'exit 1'
You can’t perform that action at this time.