Skip to content
Permalink
Newer
Older
100644 99 lines (95 sloc) 3.2 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'
22
}
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
}
32
}
33
stage('Clean') {
34
steps {
35
script {
36
try{
37
sh 'bin/destroy.sh >> debug'
38
} catch(error) {
39
def error_details = readFile('./debug');
40
def message = "BUILD ERROR: There was a problem building the Base Image. \n\n ${error_details}"
41
sh "rm -f ./debug"
42
handleError(message)
43
}
44
}
45
}
46
}
47
stage('Build') {
48
steps {
49
script {
50
sh 'midpoint/download-midpoint'
51
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
52
def baseImg = docker.build("$maintainer/$imagename", "--no-cache midpoint/midpoint-server")
53
try {
54
sh 'docker pull tier/mariadb:mariadb10' // temporary
55
sh 'env NOCOLOR=true ./test.sh'
56
} finally {
57
sh './cleanup.sh'
58
}
59
baseImg.push("$tag")
60
}
61
}
62
}
63
}
64
stage('Notify') {
65
steps {
66
echo "$maintainer"
67
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub"
68
}
69
}
70
}
71
post {
72
always {
73
echo 'Done Building.'
74
}
75
failure {
76
// slackSend color: 'good', message: "Build failed"
77
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename}:${tag}.")
78
}
79
}
80
}
81
82
83
def maintain() {
84
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
85
matcher ? matcher[0][1] : 'tier'
86
}
87
88
def imagename() {
89
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
90
matcher ? matcher[0][1] : null
91
}
92
93
def handleError(String message){
94
echo "${message}"
95
currentBuild.setResult("FAILED")
96
slackSend color: 'danger', message: "${message}"
97
//step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chubing@internet2.edu', sendToIndividuals: true])
98
sh 'exit 1'
99
}
You can’t perform that action at this time.