-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
162 lines (147 loc) · 6.24 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
150
151
152
153
154
155
156
157
158
159
160
161
162
pipeline {
agent {
label "maven"
}
options {
skipDefaultCheckout()
disableConcurrentBuilds()
}
stages {
stage("Checkout") {
steps {
library(identifier: "openshift-pipeline-library@master",
retriever: modernSCM([$class: "GitSCMSource",
credentialsId: "dev-repository-credentials",
remote: "ssh://git@github.com/leandroberetta/openshift-cicd-demo.git"]))
initParameters()
gitClone()
stash "repo"
}
}
stage("Compile") {
steps {
sh "mvn package -DskipTests"
}
}
stage("Test") {
steps {
sh "mvn test"
}
}
stage("Build Image") {
steps {
applyTemplate(project: env.DEV_PROJECT,
application: env.APP_NAME,
template: env.APP_TEMPLATE,
parameters: env.APP_TEMPLATE_PARAMETERS_DEV,
createBuildObjects: true)
buildImage(project: env.DEV_PROJECT,
application: env.APP_NAME,
artifactsDir: "./target")
}
}
stage("Deploy DEV") {
steps {
script {
env.TAG_NAME = readMavenPom().getVersion()
}
tagImage(srcProject: env.DEV_PROJECT,
srcImage: env.IMAGE_NAME,
srcTag: "latest",
dstProject: env.DEV_PROJECT,
dstImage: env.IMAGE_NAME,
dstTag: env.TAG_NAME)
deployImage(project: env.DEV_PROJECT,
application: env.APP_NAME,
image: env.IMAGE_NAME,
tag: env.TAG_NAME)
}
}
stage("Deploy TEST") {
steps {
input("Promote to TEST?")
applyTemplate(project: env.TEST_PROJECT,
application: env.APP_NAME,
template: env.APP_TEMPLATE,
parameters: env.APP_TEMPLATE_PARAMETERS_TEST)
tagImage(srcProject: env.DEV_PROJECT,
srcImage: env.IMAGE_NAME,
srcTag: env.TAG_NAME,
dstProject: env.TEST_PROJECT,
dstImage: env.IMAGE_NAME,
dstTag: env.TAG_NAME)
deployImage(project: env.TEST_PROJECT,
application: env.APP_NAME,
image: env.IMAGE_NAME,
tag: env.TAG_NAME)
}
}
stage("Integration Test") {
agent {
kubernetes {
cloud "openshift"
defaultContainer "jnlp"
label "${env.APP_NAME}-int-test"
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: python
image: python:3
command:
- cat
tty: true
"""
}
}
steps {
unstash "repo"
container("python") {
sh "pip install requests"
sh "python ./src/test/python/it.py"
}
}
}
stage("Deploy PROD (Blue)") {
steps {
script {
if (!blueGreen.existsBlueGreenRoute(project: env.PROD_PROJECT, application: env.APP_NAME)) {
applyTemplate(project: env.PROD_PROJECT,
application: blueGreen.getApplication1Name(env.APP_NAME),
template: env.APP_TEMPLATE,
parameters: env.APP_TEMPLATE_PARAMETERS_PROD)
applyTemplate(project: env.PROD_PROJECT,
application: blueGreen.getApplication2Name(env.APP_NAME),
template: env.APP_TEMPLATE,
parameters: env.APP_TEMPLATE_PARAMETERS_PROD)
blueGreen.createBlueGreenRoute(project: env.PROD_PROJECT, application: env.APP_NAME)
} else {
applyTemplate(project: env.PROD_PROJECT,
application: blueGreen.getBlueApplication(project: env.PROD_PROJECT, application: env.APP_NAME),
template: env.APP_TEMPLATE,
parameters: env.APP_TEMPLATE_PARAMETERS_PROD)
}
tagImage(srcProject: env.TEST_PROJECT,
srcImage: env.IMAGE_NAME,
srcTag: env.TAG_NAME,
dstProject: env.PROD_PROJECT,
dstImage: env.IMAGE_NAME,
dstTag: env.TAG_NAME)
deployImage(project: env.PROD_PROJECT,
application: blueGreen.getBlueApplication(project: env.PROD_PROJECT, application: env.APP_NAME),
image: env.IMAGE_NAME,
tag: env.TAG_NAME)
}
}
}
stage("Deploy PROD (Green)") {
steps {
input("Switch to new version?")
script{
blueGreen.switchToGreenApplication(project: env.PROD_PROJECT, application: env.APP_NAME)
}
}
}
}
}