Skip to content
Permalink
Newer
Older
100644 112 lines (107 sloc) 3.99 KB
1
pipeline {
2
agent any
3
environment {
4
maintainer = "t"
5
imagename = 'm'
6
imagename_data = 'md'
7
tag = 'l'
8
}
9
stages {
10
stage('Setting build context') {
11
steps {
12
script {
13
maintainer = maintain()
14
imagename = imagename()
15
imagename_data = imagename_data()
16
if(env.BRANCH_NAME == "master") {
17
tag = "latest"
18
} else {
19
tag = env.BRANCH_NAME
20
}
21
if(!imagename || !imagename_data){
22
echo "You must define imagename and imagename_data in common.bash"
23
currentBuild.result = 'FAILURE'
24
}
25
sh 'mkdir -p bin'
26
sh 'mkdir -p tmp'
27
dir('tmp'){
28
git([ url: "https://github.internet2.edu/docker/util.git", credentialsId: "jenkins-github-access-token" ])
29
sh 'ls'
30
sh 'mv bin/* ../bin/.'
31
}
32
}
33
}
34
}
35
stage('Clean') {
36
steps {
37
script {
38
try{
39
sh 'bin/destroy.sh >> debug'
40
} catch(error) {
41
def error_details = readFile('./debug');
42
def message = "BUILD ERROR: There was a problem building the Base Image. \n\n ${error_details}"
43
sh "rm -f ./debug"
44
handleError(message)
45
}
46
}
47
}
48
}
49
stage('Build') {
50
steps {
51
script {
52
sh 'midpoint/download-midpoint'
53
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
54
def baseImg = docker.build("$maintainer/$imagename", "--no-cache midpoint/midpoint-server")
55
// test the environment
56
// sh 'cd test-compose && ./compose.sh'
57
// bring down after testing
58
// sh 'cd test-compose && docker-compose down'
59
baseImg.push("$tag")
60
}
61
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
62
def baseImg = docker.build("$maintainer/$imagename_data", "--no-cache midpoint/midpoint-data")
63
// test the environment
64
// sh 'cd test-compose && ./compose.sh'
65
// bring down after testing
66
// sh 'cd test-compose && docker-compose down'
67
baseImg.push("$tag")
68
}
69
}
70
}
71
}
72
stage('Notify') {
73
steps {
74
echo "$maintainer"
75
slackSend color: 'good', message: "$maintainer/$imagename:$tag and $maintainer/$imagename_data:$tag pushed to DockerHub"
76
}
77
}
78
}
79
post {
80
always {
81
echo 'Done Building.'
82
}
83
failure {
84
// slackSend color: 'good', message: "Build failed"
85
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename}:${tag} or ${maintainer}/${imagename_data}:${tag}.")
86
}
87
}
88
}
89
90
91
def maintain() {
92
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
93
matcher ? matcher[0][1] : 'tier'
94
}
95
96
def imagename() {
97
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
98
matcher ? matcher[0][1] : null
99
}
100
101
def imagename_data() {
102
def matcher = readFile('common.bash') =~ 'imagename_data="(.+)"'
103
matcher ? matcher[0][1] : null
104
}
105
106
def handleError(String message){
107
echo "${message}"
108
currentBuild.setResult("FAILED")
109
slackSend color: 'danger', message: "${message}"
110
//step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chubing@internet2.edu', sendToIndividuals: true])
111
sh 'exit 1'
112
}
You can’t perform that action at this time.