-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
149 lines (129 loc) · 5.29 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
pipeline {
agent any
stages {
stage('Build project') {
parallel {
stage('Build JVM') {
agent {
docker {
image 'maven:3.6.3-jdk-11-slim'
}
}
steps {
sh 'mvn clean package -DskipTests'
stash(includes: 'target/', name: 'target_built')
}
}
stage('Build Native') {
steps {
withCredentials(bindings: [usernamePassword(credentialsId: 'registry', passwordVariable: 'registryPassword', usernameVariable: 'registryUser')]) {
sh "docker login -u ${env.registryUser} -p ${env.registryPassword} registry.zouzland.com"
sh 'docker build -f src/main/docker/Dockerfile.native --cpuset-cpus 0,1,2 -t registry.zouzland.com/boutry/devops-tutorial-native:latest .'
}
}
}
}
}
stage('Test JVM') {
agent {
docker {
image 'maven:3.6.3-jdk-11-slim'
args '--network="host" -e DOCKER_HOST="tcp://docker:2376" -e DOCKER_CERT_PATH="/certs/client" -e DOCKER_TLS_VERIFY=1 -v "$DOCKER_CERT_PATH":"$DOCKER_CERT_PATH"'
}
}
steps {
unstash 'target_built'
sh 'mvn test'
}
}
stage('Build Docker JVM') {
agent any
steps {
unstash 'target_built'
sh 'docker build -f src/main/docker/Dockerfile.jvm -t registry.zouzland.com/boutry/devops-tutorial-jvm:latest .'
}
}
stage('Push Docker build to registry') {
agent any
when {
expression {
GIT_BRANCH = 'origin/' + sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
return GIT_BRANCH == 'origin/master' || params.FORCE_PUSH
}
}
steps {
withCredentials(bindings: [usernamePassword(credentialsId: 'registry', passwordVariable: 'registryPassword', usernameVariable: 'registryUser')]) {
sh "docker login -u ${env.registryUser} -p ${env.registryPassword} registry.zouzland.com"
script {
if(params.TAG_BUILD) {
// Push latest
sh 'docker push registry.zouzland.com/boutry/devops-tutorial-jvm:latest'
sh 'docker push registry.zouzland.com/boutry/devops-tutorial-native:latest'
// Tag latest with version
sh 'docker tag registry.zouzland.com/boutry/devops-tutorial-jvm:latest registry.zouzland.com/boutry/devops-tutorial-jvm:' + params.TAG
sh 'docker tag registry.zouzland.com/boutry/devops-tutorial-jvm:latest registry.zouzland.com/boutry/devops-tutorial-native:' + params.TAG
// Push tagged version
sh 'docker push registry.zouzland.com/boutry/devops-tutorial-jvm:' + params.TAG
sh 'docker push registry.zouzland.com/boutry/devops-tutorial-native:' + params.TAG
} else {
// Tag latest as Snapshot
sh 'docker tag registry.zouzland.com/boutry/devops-tutorial-jvm:latest registry.zouzland.com/boutry/devops-tutorial-jvm:snapshot'
sh 'docker tag registry.zouzland.com/boutry/devops-tutorial-native:latest registry.zouzland.com/boutry/devops-tutorial-native:snapshot'
// Push to registry
sh 'docker push registry.zouzland.com/boutry/devops-tutorial-jvm:snapshot'
sh 'docker push registry.zouzland.com/boutry/devops-tutorial-native:snapshot'
}
}
}
}
}
stage('Deploy release to heroku') {
when {
expression {
return params.TAG_BUILD
}
}
agent {
docker {
image 'registry.zouzland.com/heroku-ctn:latest'
registryCredentialsId 'registry'
args '--network="host" -e DOCKER_HOST="tcp://docker:2376" -e DOCKER_CERT_PATH="/certs/client" -e DOCKER_TLS_VERIFY=1 -v "$DOCKER_CERT_PATH":"$DOCKER_CERT_PATH"'
}
}
steps {
withCredentials(bindings: [usernamePassword(credentialsId: 'registry', passwordVariable: 'registryPassword', usernameVariable: 'registryUser')]) {
sh "docker login -u ${env.registryUser} -p ${env.registryPassword} registry.zouzland.com"
sh 'docker pull registry.zouzland.com/boutry/devops-tutorial-native:' + params.TAG
sh 'docker tag registry.zouzland.com/boutry/devops-tutorial-native:' + params.TAG + " registry.heroku.com/devops-tutorial/web"
}
withCredentials(bindings: [string(credentialsId: 'heroku_token', variable: 'HEROKU_API_KEY')]) {
sh "heroku container:login"
sh "docker push registry.heroku.com/devops-tutorial/web"
sh "heroku container:release web -a devops-tutorial"
}
}
}
}
post {
always {
deleteDir()
}
success {
echo 'BUILD SUCCESS'
}
unstable {
echo 'BUILD UNSTABLE'
}
failure {
echo 'BUILD FAILURE'
}
changed {
echo 'State changed.'
}
}
parameters {
booleanParam(defaultValue: false, description: 'Push docker image to registry', name: 'FORCE_PUSH')
booleanParam(defaultValue: false, description: 'Tag current build ?', name: 'TAG_BUILD')
string(defaultValue: 'latest', description: 'TAG number', name: 'TAG')
}
}