Permalink
Newer
100644
118 lines (113 sloc)
4.59 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" ])
32
// Build and test scripts expect that 'tag' is present in common.bash. This is necessary for both Jenkins and standalone testing.
33
// We don't care if there are more 'tag' assignments there. The latest one wins.
34
sh "echo >> common.bash ; echo \"tag=\\\"${tag}\\\"\" >> common.bash ; echo common.bash ; cat common.bash"
42
// using custom ./build.sh instead of bin/rebuild.sh because the bin/ version does not support building specific tag yet
43
sh './build.sh -r 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
44
} catch (error) {
45
def error_details = readFile('./debug')
46
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
47
sh "rm -f ./debug"
48
handleError(message)
49
}
50
}
51
}
52
}
53
stage ('Test') {
54
steps {
55
script {
56
try {
57
sh 'echo Docker containers before root tests ; docker ps -a' // temporary
58
sh 'bin/test.sh 2>&1 | tee debug ; test ${PIPESTATUS[0]} -eq 0'
59
sh 'echo Docker containers before compositions tests ; docker ps -a' // temporary
60
61
sh '(cd demo/simple ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
62
// sh '(cd demo/shibboleth ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
63
sh '(cd demo/postgresql ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
64
sh '(cd demo/complex ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
67
def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}"
78
def baseImg = docker.build("$maintainer/$imagename")
79
baseImg.push("$tag")
80
}
81
}
88
}
89
}
90
}
91
post {
92
always {
93
echo 'Done Building.'
94
}
95
failure {
96
// slackSend color: 'good', message: "Build failed"
97
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename}:${tag}.")
104
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
105
matcher ? matcher[0][1] : 'tier'
109
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
110
matcher ? matcher[0][1] : null
113
def handleError(String message) {
114
echo "${message}"
115
currentBuild.setResult("FAILED")
116
slackSend color: 'danger', message: "${message}"
117
sh 'exit 1'