This repository has been archived by the owner on Mar 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
101 lines (88 loc) · 2.73 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
#!/usr/bin/groovy
@Library('github.com/fabric8io/fabric8-pipeline-library@master')
import io.fabric8.Fabric8Commands
def utils = new io.fabric8.Utils()
clientsNode{
def envStage = utils.environmentNamespace('stage')
def newVersion = ''
def resourceName = utils.getRepoName()
checkout scm
stage('Build Release')
echo 'NOTE: running pipelines for the first time will take longer as build and base docker images are pulled onto the node'
container('clients') {
if (newVersion == '') {
newVersion = getNewVersion {}
}
env.setProperty('VERSION', newVersion)
def flow = new Fabric8Commands()
if (flow.isOpenShift()) {
def ns = utils.namespace
def is = """
apiVersion: v1
kind: ImageStream
metadata:
name: ${resourceName}
namespace: ${ns}
"""
def bc = """
apiVersion: v1
kind: BuildConfig
metadata:
name: ${resourceName}-s2i
namespace: ${ns}
spec:
output:
to:
kind: ImageStreamTag
name: ${resourceName}:${newVersion}
resources:
limits:
memory: '1024Mi'
runPolicy: Serial
source:
type: Binary
strategy:
sourceStrategy:
env:
- name: ADD_REST_ENDPOINTS
value: 'true'
- name: JAVA_TOOL_OPTIONS
value: '-Xmx800m'
from:
kind: "DockerImage"
name: "ceylon/s2i-ceylon:1.3.3-jre8"
"""
sh "oc delete is ${resourceName} -n ${ns} || true"
kubernetesApply(file: is, environment: ns)
kubernetesApply(file: bc, environment: ns)
sh "oc start-build ${resourceName}-s2i --from-dir ./ --follow -n ${ns}"
} else {
echo 'NOTE: Not on Openshift: do nothing since it is not implemented for now'
}
}
stage('Rollout to Stage')
def migrationImage = "${resourceName}:${newVersion}"
def isSha = utils.getImageStreamSha(resourceName)
def ns = utils.namespace
def isForDeployment = """
apiVersion: v1
kind: ImageStream
metadata:
name: ${resourceName}
spec:
tags:
- from:
kind: ImageStreamImage
name: ${resourceName}@${isSha}
namespace: ${utils.getNamespace()}
name: ${newVersion}
"""
echo "About to apply the following to openshift: ${isForDeployment}"
kubernetesApply(file: isForDeployment, environment: envStage)
def migrationCM = sh(returnStdout: true, script: "oc process -f migration-cm.yml")
echo "About to apply the following to openshift: ${migrationCM}"
kubernetesApply(file: migrationCM, environment: envStage)
def deployment = sh(returnStdout: true, script: "oc process -f migration-endpoints.yml -v IMAGE=\"${migrationImage}\" -v IMAGE_NAMESPACE_PREFIX=\"\" -v VERSION=\"${newVersion}\"")
echo "About to apply the following to openshift: ${deployment}"
kubernetesApply(file: deployment, environment: envStage)
}