-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathmulti-namespace-pipeline.yaml
80 lines (71 loc) · 2.91 KB
/
multi-namespace-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
apiVersion: template.openshift.io/v1
kind: Template
labels:
template: multi-namespace-pipeline
metadata:
annotations:
iconClass: icon-jenkins
tags: instant-app,jenkins
name:
parameters:
- description: namespace
displayName: namespace
name: NAMESPACE
value: namespace
- description: namespace2
displayName: namespace2
name: NAMESPACE2
value: namespace2
- description: namespace3
displayName: namespace3
name: NAMESPACE3
value: namespace3
objects:
- apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
labels:
name: multi-namespace-pipeline
name: multi-namespace-pipeline
spec:
strategy:
jenkinsPipelineStrategy:
env:
- name: NAMESPACE
value: ${NAMESPACE}
- name: NAMESPACE2
value: ${NAMESPACE2}
- name: NAMESPACE3
value: ${NAMESPACE3}
jenkinsfile: |-
try {
timeout(time: 20, unit: 'MINUTES') {
// Select the default cluster
openshift.withCluster() {
// Select the default project
openshift.withProject() {
// Output the url of the currently selected cluster
echo "Using project ${openshift.project()} in cluster with url ${openshift.cluster()}"
template = openshift.create('https://raw.githubusercontent.com/openshift/origin/master/test/extended/testdata/multi-namespace-template.yaml').object()
// Explore the Groovy object which models the OpenShift template as a Map
echo "Template contains ${template.parameters.size()} parameters"
// Process the modeled template. We could also pass JSON/YAML, a template name, or a url instead.
def objectModels = openshift.process( template, "-p", "NAMESPACE=${env.NAMESPACE}", "-p", "NAMESPACE2=${env.NAMESPACE2}", "-p", "NAMESPACE3=${env.NAMESPACE3}" )
// objectModels is a list of objects the template defined, modeled as Groovy objects
echo "The template references ${objectModels.size()} objects"
def objects = openshift.create(objectModels)
// Create returns a selector which will always select the objects created
objects.withEach {
// Each loop binds the variable 'it' to a selector which selects a single object
echo "Created ${it.name()} from template with labels ${it.object().metadata.labels}"
}
}
}
}
} catch (err) {
echo "in catch block"
echo "Caught: ${err}"
currentBuild.result = 'FAILURE'
throw err
}
type: JenkinsPipeline