forked from electric-cloud/DSL-Samples
-
Notifications
You must be signed in to change notification settings - Fork 6
/
YamlImport.groovy
42 lines (37 loc) · 966 Bytes
/
YamlImport.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
import groovy.yaml.*
def configYaml = '''\
pipelines:
- name: My Pipeline
project: Default
stages:
- name: QA
tasks:
- name: Run test
type: command
command: echo testing...
- name: UAT
gates:
- name: QA approval
approvers:
- qa
'''
def config = new YamlSlurper().parseText(configYaml)
String dsl=""
config.pipelines.each { pipeline ->
dsl += "pipeline \"${pipeline.name}\", projectName: \"${pipeline.project}\"" + ',{\n'
pipeline.stages.each { stage ->
dsl += "\n\tstage \"${stage.name}\"" + ',{\n'
stage.gates.each { gate ->
dsl += "\n\t\tgate \"${gate.name}\"" + ',{\n'
dsl += '\n\t\t}'
}
stage.tasks.each { task ->
dsl += "\n\t\ttask \"${task.name}\"" + ',{\n'
dsl += '\n\t\t}'
}
dsl += '\n\t}'
}
dsl += '\n}'
}
dsl