Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Newer
Older
100644 84 lines (78 sloc) 2.38 KB
August 3, 2018 16:55
1
pipeline {
2
agent any
3
environment {
4
maintainer = "t"
5
imagename = 'g'
6
tag = 'l'
7
version='3.1.1'
8
}
9
stages {
10
stage('Setting build context') {
11
steps {
12
script {
13
maintainer = maintain()
14
imagename = imagename()
15
version= registryversion()
16
if(env.BRANCH_NAME == "master") {
17
tag = "latest"
18
} else {
19
tag = env.BRANCH_NAME
20
}
21
if(!imagename){
22
echo "You must define an imagename in common.bash"
23
currentBuild.result = 'FAILURE'
24
}
25
}
26
}
27
}
28
stage('Build') {
29
steps {
30
echo 'step 2'
31
}
32
}
33
stage('Push') {
34
steps {
35
script {
36
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
37
def baseImg = docker.build("$maintainer/$imagename", "--build-arg COMANAGE_REGISTRY_VERSION=$version .")
38
baseImg.push("$tag")
39
}
40
}
41
}
42
}
43
stage('Notify') {
44
steps{
45
echo "$maintainer"
46
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub"
47
}
48
}
49
}
50
post {
51
always {
52
echo 'In post.'
53
}
54
failure {
55
// slackSend color: 'good', message: "Build failed"
56
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename}:${tag}.")
57
}
58
}
59
}
60
61
62
def maintain() {
63
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
64
matcher ? matcher[0][1] : 'tier'
65
}
66
67
def imagename() {
68
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
69
matcher ? matcher[0][1] : null
70
}
71
72
def registryversion() {
73
def matcher = readFile('common.bash') =~ 'COMANAGE_REGISTRY_VERSION="(.+)"'
74
matcher ? matcher[0][1] : null
75
}
76
77
78
def handleError(String message){
79
echo "${message}"
80
currentBuild.setResult("FAILED")
81
slackSend color: 'danger', message: "${message}"
82
//step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chubing@internet2.edu', sendToIndividuals: true])
83
sh 'exit 1'
84
}