Skip to content
Permalink
Newer
Older
100644 119 lines (112 sloc) 4.41 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 '(ls -l ; docker ps -a ; docker image ls ; echo Destroying ; bin/destroy.sh ; docker image ls) 2>&1 | tee debug' // temporary
38
sh './download-midpoint 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
39
sh 'bin/rebuild.sh 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
Sep 28, 2018
40
//sh 'echo Build output ; cat debug'
41
} catch (error) {
42
def error_details = readFile('./debug')
43
def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}"
44
sh "rm -f ./debug"
45
handleError(message)
46
}
47
}
48
}
49
}
50
stage ('Test') {
51
steps {
52
script {
53
try {
54
sh 'echo Docker containers before root tests ; docker ps -a' // temporary
55
sh 'bin/test.sh 2>&1 | tee debug ; test ${PIPESTATUS[0]} -eq 0'
56
sh 'echo Docker containers before compositions tests ; docker ps -a' // temporary
57
58
sh '(cd demo/simple ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
Oct 1, 2018
59
60
// temporarily disabled
61
//sh '(cd demo/shibboleth ; 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'
Sep 28, 2018
64
// sh 'echo Test output ; cat debug'
65
} catch (error) {
66
def error_details = readFile('./debug')
67
def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}"
68
sh "rm -f ./debug"
69
handleError(message)
70
}
71
}
72
}
73
}
74
/* stage ('Push') {
75
steps {
76
script {
77
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
78
def baseImg = docker.build("$maintainer/$imagename")
79
baseImg.push("$tag")
80
}
81
}
82
}
83
}
85
stage ('Notify') {
86
steps {
87
echo "$maintainer"
88
slackSend color: 'good', message: "$maintainer/$imagename:$tag built but NOT pushed to DockerHub (push temporarily disabled for this branch)"
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.