-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathmaven-pipeline.yaml
291 lines (284 loc) · 8.14 KB
/
maven-pipeline.yaml
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
apiVersion: template.openshift.io/v1
kind: Template
metadata:
name: maven-pipeline
parameters:
- name: APP_NAME
description: The name assigned to all of the application objects defined in this template.
displayName: Application Name
required: true
value: openshift-jee-sample
- name: GIT_SOURCE_URL
description: The source URL for the application
displayName: Source URL
required: true
value: https://github.com/openshift/openshift-jee-sample.git
- name: GIT_SOURCE_REF
description: The source Ref for the application
displayName: Source Ref
required: true
value: master
- description: Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.
displayName: GitHub Webhook Secret
from: '[a-zA-Z0-9]{40}'
generate: expression
name: GITHUB_WEBHOOK_SECRET
required: true
- description: A secret string used to configure the Generic webhook.
displayName: Generic Webhook Secret
from: '[a-zA-Z0-9]{40}'
generate: expression
name: GENERIC_WEBHOOK_SECRET
required: true
objects:
- apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
labels:
app: ${APP_NAME}
name: ${APP_NAME}
spec: {}
status:
dockerImageRepository: ""
- apiVersion: image.openshift.io/fv1
kind: ImageStream
metadata:
name: wildfly
spec:
tags:
- annotations:
supports: wildfly:10.1,jee,java
tags: builder,wildfly,java
version: "10.1"
from:
kind: DockerImage
name: openshift/wildfly-101-centos7:latest
name: "10.1"
- annotations:
supports: jee,java
tags: builder,wildfly,java
from:
kind: ImageStreamTag
name: "10.1"
name: latest
- apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
annotations:
pipeline.alpha.openshift.io/uses: '[{"name": "${NAME}", "namespace": "", "kind": "DeploymentConfig"}]'
creationTimestamp: null
labels:
name: ${APP_NAME}
name: ${APP_NAME}
spec:
strategy:
jenkinsPipelineStrategy:
jenkinsfile: |-
try {
timeout(time: 20, unit: 'MINUTES') {
def appName="${APP_NAME}"
def project=""
node {
stage("Initialize") {
project = env.PROJECT_NAME
}
}
node("maven") {
stage("Checkout") {
git url: "${GIT_SOURCE_URL}", branch: "${GIT_SOURCE_REF}"
}
stage("Build WAR") {
sh "mvn clean package -Popenshift"
stash name:"war", includes:"target/ROOT.war"
}
}
node {
stage("Build Image") {
unstash name:"war"
def status = sh(returnStdout: true, script: "oc start-build ${appName}-docker --from-file=target/ROOT.war -n ${project}")
def result = status.split("\n").find{ it.matches("^build.*started") }
if(!result) {
echo "ERROR: No started build found for ${appName}"
currentBuild.result = 'FAILURE'
return
}
// result can be:
// - build "build-name" started
// - build build.build.openshift.io/build-name started
// - build "build.build.openshift.io/build-name" started
// Goal is to isolate "build-name"
def startedBuild = result.replaceAll("build [^0-9a-zA-Z]*", "").replaceAll("[^0-9a-zA-Z]* started", "").replaceFirst("^.*/", "")
echo "Build ${startedBuild} has started. Now watching it ..."
timeout(time: 20, unit: 'MINUTES') {
openshift.withCluster() {
openshift.withProject() {
def build = openshift.selector('builds', "${startedBuild}")
build.untilEach {
def object = it.object()
if(object.status.phase == "Failed") {
error("Build ${startedBuild} failed")
}
return object.status.phase == "Complete"
}
}
}
}
}
stage("Deploy") {
openshift.withCluster() {
openshift.withProject() {
def dc = openshift.selector('dc', "${appName}")
dc.rollout().status()
}
}
}
}
}
} catch (err) {
echo "in catch block"
echo "Caught: ${err}"
currentBuild.result = 'FAILURE'
throw err
}
type: JenkinsPipeline
triggers:
- github:
secret: "${GITHUB_WEBHOOK_SECRET}"
type: GitHub
- generic:
secret: "${GENERIC_WEBHOOK_SECRET}"
type: Generic
- apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
labels:
app: ${APP_NAME}-docker
name: ${APP_NAME}-docker
spec:
output:
to:
kind: ImageStreamTag
name: ${APP_NAME}:latest
postCommit: {}
resources: {}
runPolicy: Serial
source:
dockerfile: |-
FROM wildfly
COPY ROOT.war /wildfly/standalone/deployments/ROOT.war
CMD $STI_SCRIPTS_PATH/run
binary:
asFile: ROOT.war
type: Docker
strategy:
dockerStrategy:
from:
kind: ImageStreamTag
name: wildfly:latest
type: Docker
triggers: []
- apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
labels:
app: ${APP_NAME}
name: ${APP_NAME}
spec:
replicas: 1
selector:
app: ${APP_NAME}
deploymentconfig: ${APP_NAME}
strategy:
rollingParams:
intervalSeconds: 1
maxSurge: 25%
maxUnavailable: 25%
timeoutSeconds: 600
updatePeriodSeconds: 1
type: Rolling
template:
metadata:
labels:
app: ${APP_NAME}
deploymentconfig: ${APP_NAME}
spec:
containers:
- image: ${APP_NAME}:latest
imagePullPolicy: Always
name: ${APP_NAME}
ports:
- containerPort: 8080
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
livenessProbe:
httpGet:
path: /
port: 8080
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 2
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
readinessProbe:
httpGet:
path: /
port: 8080
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 2
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds: 30
test: false
triggers:
- type: ConfigChange
- imageChangeParams:
automatic: true
containerNames:
- ${APP_NAME}
from:
kind: ImageStreamTag
name: ${APP_NAME}:latest
type: ImageChange
status: {}
- apiVersion: v1
kind: Service
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
labels:
app: ${APP_NAME}
name: ${APP_NAME}
spec:
ports:
- name: 8080-tcp
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: ${APP_NAME}
deploymentconfig: ${APP_NAME}
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: ${APP_NAME}
labels:
app: ${APP_NAME}
spec:
to:
kind: Service
name: ${APP_NAME}
weight: 100
port:
targetPort: 8080-tcp
wildcardPolicy: None