-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-example
181 lines (135 loc) · 6.76 KB
/
Jenkinsfile-example
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
#!/usr/bin/env groovy
//@Library("[email protected]") _
// we want both liberies in global namespace
@Library(["[email protected]", "[email protected]"]) _
//override standard param example
println(getTemplate('jnlp': [:], 'util':[imagePullPolicy: "ifnotpresent"]))
println("==========================")
//tag will override image tag from template
println(getTemplate('jnlp': [:], 'util': [tag: "lolo"]))
println("==========================")
//add multiple same containers
println(getTemplate('jnlp': [:], 'util': [names: ["foo","bar"]]))
println("==========================")
//add multiple same containers with override
println(getTemplate('jnlp': [:], 'util': [names: ["foo","bar"], resources:[ requests: [memory: '200m']]]))
println("===========NORMAL===============")
//add multiple same containers with override
println(getTemplate('jnlp': [:], 'util': [names: ["foo","bar"], resources:[ requests: [memory: '665m']]]))
println("===========DOTNOTED===============")
//add multiple same containers with override
println(getTemplate('jnlp': [:], 'util': [names: ["foo","bar"], 'resources.requests.memory': '665m', env: ["TOMBO=kombo", "mambo=jAmBo"], vol:[ ['type':'configmap','name': 'my-configmap-name','path' :'/var/log' ] ] ]))
println("==================================")
//without predefined template
println(getTemplate('foobar': ['image':'docker.io/dummyimage:v666']))
podTemplate(yaml: getTemplate('jnlp': [:], 'util': [names: ["foo","bar"], resources:[ requests: [memory: '200m']]]) {
node(POD_LABEL) {
container('util') {
sh "echo here;sleep 60"
}
}
}
podTemplate(yaml: getTemplate('jnlp': [:], 'util': [names: ["foo","bar"], envs: ['myenv':'myenvval','mynumber': 3]]) {
node(POD_LABEL) {
container('util') {
sh "echo here;sleep 60"
}
}
}
// REAL WORLD EXAMPLE with 2x kaniko containers, exmaple volume mount for kaniko
// we will refer to multiple kaniko conatiner by name eg:
//
// pfDocker.getKanikoJobDef(
// runInContainer: 'k1'
// ...
// )
// and
// pfDocker.getKanikoJobDef(
// runInContainer: 'k2'
// ...
// )
String podTemplateName = "my-exmaple-ci"
String podTemplateIdleMinutes = "10"
String podTemplateYaml = getTemplate('jnlp': [:], 'util': [:], 'kaniko': [names: ["k1", "k2"],
vol: [[type: 'configmap', name: 'kaniko-ecr-helper-config', path: '/kaniko/.docker/']]])
Map podTemplateConf = [ name: "${podTemplateName}", idleMinutes: "${podTemplateIdleMinutes}", slaveConnectTimeout: 100, instanceCap: 1, yaml: podTemplateYaml ]
podTemplate( podTemplateConf ) {
node( POD_LABEL ) {
}
}
// SHORTHAND usage just `util` container
podTemplateName = "my-shorthand-exmaple-ci"
podTemplateIdleMinutes = "5"
podTemplateYaml = getTemplate.Util()
podTemplateConf = [ name: "${podTemplateName}", idleMinutes: "${podTemplateIdleMinutes}", slaveConnectTimeout: 100, instanceCap: 1, yaml: podTemplateYaml ]
podTemplate( podTemplateConf ) {
node( POD_LABEL ) {
}
}
// SHORTHAND usage util and builx container
podTemplateName = "my-shorthand-exmaple-2-ci"
podTemplateIdleMinutes = "5"
podTemplateYaml = getTemplate.UtilBuildx()
podTemplateConf = [ name: "${podTemplateName}", idleMinutes: "${podTemplateIdleMinutes}", slaveConnectTimeout: 100, instanceCap: 1, yaml: podTemplateYaml ]
podTemplate( podTemplateConf ) {
node( POD_LABEL ) {
}
}
// SHORTHAND usage util and builx and php container
podTemplateName = "my-shorthand-exmaple-2-ci"
podTemplateIdleMinutes = "5"
podTemplateYaml = getTemplate.UtilBuildxPhp()
podTemplateConf = [ name: "${podTemplateName}", idleMinutes: "${podTemplateIdleMinutes}", slaveConnectTimeout: 100, instanceCap: 1, yaml: podTemplateYaml ]
podTemplate( podTemplateConf ) {
node( POD_LABEL ) {
}
}
// SHORTHAND usage util and kaniko container
podTemplateName = "my-shorthand-exmaple-2-ci"
podTemplateIdleMinutes = "5"
podTemplateYaml = getTemplate.UtilKaniko()
podTemplateConf = [ name: "${podTemplateName}", idleMinutes: "${podTemplateIdleMinutes}", slaveConnectTimeout: 100, instanceCap: 1, yaml: podTemplateYaml ]
podTemplate( podTemplateConf ) {
node( POD_LABEL ) {
}
}
// SHORTHAND for util-kaniko-php pod, php template has default image `php-fpm:7.4.16-buster-build"` so you can use getTemplate.UtilKanikoPhp()
// preferably you want to specify php image, so stick with getTemplate.Util() or getTemplate.UtilKaniko() and define your override for php template as in example
podTemplateName = "my-shorthand-exmaple-2-ci"
podTemplateIdleMinutes = "5"
podTemplateYaml = getTemplate.UtilKaniko('php':[image: "266775278674.dkr.ecr.eu-west-1.amazonaws.com/php-fpm:7.4.16-buster-build"])
podTemplateConf = [ name: "${podTemplateName}", idleMinutes: "${podTemplateIdleMinutes}", slaveConnectTimeout: 100, instanceCap: 1, yaml: podTemplateYaml ]
podTemplate( podTemplateConf ) {
node( POD_LABEL ) {
}
}
//OR shorter variant with overriding just php template tag
podTemplateName = "my-shorthand-exmaple-2-tag-ci"
podTemplateIdleMinutes = "5"
podTemplateYaml = getTemplate.UtilKaniko('php':[tag: "php-fpm:7.4.16-buster-build"])
podTemplateConf = [ name: "${podTemplateName}", idleMinutes: "${podTemplateIdleMinutes}", slaveConnectTimeout: 100, instanceCap: 1, yaml: podTemplateYaml ]
podTemplate( podTemplateConf ) {
node( POD_LABEL ) {
}
}
// SHORTHAND for util-4xkaniko-php pod
podTemplateName = "my-shorthand-exmaple-2-ci"
podTemplateIdleMinutes = "5"
podTemplateYaml = getTemplate.Util('php':[tag: "php-fpm:7.4.16-buster-build"], 'kaniko': [names: ["ka0", "ka1", "ka2", "ka3"]])
podTemplateConf = [ name: "${podTemplateName}", idleMinutes: "${podTemplateIdleMinutes}", slaveConnectTimeout: 100, instanceCap: 1, yaml: podTemplateYaml ]
podTemplate( podTemplateConf ) {
node( POD_LABEL ) {
}
}
// HOW TO OVERRIDE POD TEMPLATE WITH DOTT NOTATION
podTemplateYaml = getTemplate.Util([:], ['spec.nodeSelector.foo': 'bar' ])
//HOW TO OVERRIDE POD TEMPLATE WITH DOTT NOTATION AND DELETE EXISTING WITH NULL
getTemplate.UtilBuildxPhp([:], ['spec.nodeSelector.dedicated' : null , 'spec.nodeSelector.foo': 'bar' ])
//HOW TO OVERRIDE POD TEMPLATE WITH MULTIPLE KEYS
getTemplate.UtilBuildxPhp([:], ['spec.nodeSelector.foo' : 'bar' , 'spec.serviceAccountName': 'test' ])
//HOW TO OVERRIDE POD TEMPLATE WITH MAP
getTemplate.UtilBuildxPhp([:], ['spec': ['nodeSelector': ['foo' : 'bar'] , 'serviceAccountName': 'test' ]])
//HOW TO OVERRIDE POD TEMPLATE WITH MAP AND DELETE KEY
getTemplate.UtilBuildxPhp([:], ['spec': ['nodeSelector': ['foo' : 'bar', 'dedicated': null] , 'serviceAccountName': 'test' ]])
//ADD UTIL AND MULTIPLE SAME KANIKO CONTAINERS WITH DIFERENT NAMES, REMOVE EXISTING SELECTOR, ADD NEW SELECTOR, CHANGE SERVICE ACCOUNT
getTemplate.Jnlp('util': [:], 'kaniko': [names: ["k1", "k2"]], ['spec.nodeSelector.dedicated' : null , 'spec.nodeSelector.foo': 'bar' , 'spec.serviceAccountName' : 'foobar' ])