Permalink
Newer
100644
117 lines (112 sloc)
4.56 KB
1
pipeline {
2
agent any
3
environment {
4
maintainer = "t"
5
imagename = 'm'
6
tag = 'l'
7
}
8
stages {
25
dir ('tmp') {
26
git([ url: "https://github.internet2.edu/docker/util.git", credentialsId: "jenkins-github-access-token" ])
31
// Build and test scripts expect that 'tag' is present in common.bash. This is necessary for both Jenkins and standalone testing.
32
// We don't care if there are more 'tag' assignments there. The latest one wins.
33
sh "echo >> common.bash ; echo \"tag=\\\"${tag}\\\"\" >> common.bash ; echo common.bash ; cat common.bash"
41
// using custom ./build.sh instead of bin/rebuild.sh because the bin/ version does not support building specific tag yet
42
sh './build.sh -r 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
43
} catch (error) {
44
def error_details = readFile('./debug')
45
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
46
sh "rm -f ./debug"
47
handleError(message)
48
}
49
}
50
}
51
}
52
stage ('Test') {
53
steps {
54
script {
55
try {
56
sh 'echo Docker containers before root tests ; docker ps -a' // temporary
57
sh 'bin/test.sh 2>&1 | tee debug ; test ${PIPESTATUS[0]} -eq 0'
58
sh 'echo Docker containers before compositions tests ; docker ps -a' // temporary
59
60
sh '(cd demo/simple ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
61
sh '(cd demo/shibboleth ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
62
sh '(cd demo/postgresql ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
63
sh '(cd demo/complex ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
66
def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}"
77
def baseImg = docker.build("$maintainer/$imagename")
78
baseImg.push("$tag")
79
}
80
}
87
}
88
}
89
}
90
post {
91
always {
92
echo 'Done Building.'
93
}
94
failure {
95
// slackSend color: 'good', message: "Build failed"
96
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename}:${tag}.")
103
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
104
matcher ? matcher[0][1] : 'tier'
108
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
109
matcher ? matcher[0][1] : null
112
def handleError(String message) {
113
echo "${message}"
114
currentBuild.setResult("FAILED")
115
slackSend color: 'danger', message: "${message}"
116
sh 'exit 1'