-
Notifications
You must be signed in to change notification settings - Fork 210
/
goTemplate.groovy
63 lines (56 loc) · 3.06 KB
/
goTemplate.groovy
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
#!/usr/bin/groovy
import io.fabric8.Fabric8Commands
def call(Map parameters = [:], body) {
def flow = new Fabric8Commands()
def defaultLabel = buildId('go')
def label = parameters.get('label', defaultLabel)
def goImage = parameters.get('goImage', 'fabric8/go-builder:1.8.1.2')
def clientsImage = parameters.get('clientsImage', 'fabric8/builder-clients:vf422ab0')
def inheritFrom = parameters.get('inheritFrom', 'base')
def jnlpImage = (flow.isOpenShift()) ? 'fabric8/jenkins-slave-base-centos7:0.0.1' : 'jenkinsci/jnlp-slave:2.62'
def utils = new io.fabric8.Utils()
// 0.13 introduces a breaking change when defining pod env vars so check version before creating build pod
if (utils.isKubernetesPluginVersion013()) {
podTemplate(label: label, serviceAccount: 'jenkins', inheritFrom: "${inheritFrom}",
containers: [
containerTemplate(
name: 'go',
image: "${goImage}",
command: '/bin/sh -c',
args: 'cat',
ttyEnabled: true,
workingDir: '/home/jenkins/',
envVars: [
envVar(key: 'GOPATH', value: '/home/jenkins/go')
]),
containerTemplate(
name: 'clients',
image: "${clientsImage}",
command: 'cat',
ttyEnabled: true)
],
volumes:
[secretVolume(secretName: 'jenkins-hub-api-token', mountPath: '/home/jenkins/.apitoken'),
secretVolume(secretName: 'jenkins-ssh-config', mountPath: '/root/.ssh'),
secretVolume(secretName: 'jenkins-git-ssh', mountPath: '/root/.ssh-git')
]) {
body()
}
} else {
podTemplate(label: label, serviceAccount: 'jenkins', inheritFrom: "${inheritFrom}",
containers: [
//[name: 'jnlp', image: "${jnlpImage}", args: '${computer.jnlpmac} ${computer.name}', workingDir: '/home/jenkins/'],
[name: 'go', image: "${goImage}", command: '/bin/sh -c', args: 'cat', ttyEnabled: true, workingDir: '/home/jenkins/',
envVars: [
[key: 'GOPATH', value: '/home/jenkins/go']
]],
[name: 'clients', image: "${clientsImage}", command: 'cat', ttyEnabled: true]],
volumes:
[secretVolume(secretName: 'jenkins-hub-api-token', mountPath: '/home/jenkins/.apitoken'),
secretVolume(secretName: 'jenkins-ssh-config', mountPath: '/root/.ssh'),
secretVolume(secretName: 'jenkins-git-ssh', mountPath: '/root/.ssh-git')
]) {
body()
}
}
}