-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.default.1
84 lines (72 loc) · 2.4 KB
/
Jenkinsfile.default.1
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
log '''Load Jenkinsfile.default'''
node {
//def _config = pipelineConfig()
def _config = env._config
//Remove left indent
//- http://mrhaki.blogspot.kr/2010/06/groovy-goodness-strip-leading-spaces_20.html
stage('*parepare') {
echo """\
Load Jenkinsfile.default
|+ Loaded pipeline config
|${_config}
|+ Build scripted pipeline""".stripMargin()
}
// https://github.com/jenkinsci/script-security-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/blacklist
//println scm.properties
_config = yaml.load(_config)
//Check & Create slave containers
//- https://github.com/jenkinsci/kubernetes-plugin
//- https://stackoverflow.com/a/24189321
if(_config.agent?.containers){
def label = "jenkins-${UUID.randomUUID().toString()}"
def _agent = _config.agent
def _containers = []
def _volumes = []
// create container
_agent.containers.each {
_containers << containerTemplate(it)
}
// create volumes
_agent.volumes?.each {
it.each {
//Loop of collection of map
//- https://stackoverflow.com/a/43269874
//Groovy dynamic method invokation
//- http://www.groovy-lang.org/metaprogramming.html#_dynamic_method_names
_volumes << "${it.key}"(it.value)
}
}
echo _containers.join('\n')
echo _volumes.join('\n')
podTemplate(label: label, serviceAccount: 'jenkins-release', slaveConnectTimeout:30, containers: _containers, volumes: _volumes) {
node(label) {
stage('* init stage on slave container ') {
echo "init!"
}
if(_config.build){
def action = {
container(it.key) {
stage("** BUILD: ${it.key}") {
sh "${it.value}"
}
}
}
_config.build.each {
it.each action
}
}
} //node
}
}
//Build dynamic stages
_config.stage.each {
stage(it) {
echo """\
|**Load:
|${_config[it]}
|**Dump:
|${yaml.dump([(it): _config[it]])}
""".stripMargin()
}
}
}