-
Notifications
You must be signed in to change notification settings - Fork 10
/
YamlFileLoader.groovy
40 lines (32 loc) · 997 Bytes
/
YamlFileLoader.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
package org.jenkinsci.plugins.yamlaxis
import groovy.transform.TupleConstructor
import hudson.FilePath
import hudson.Util
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.SafeConstructor
@TupleConstructor
class YamlFileLoader extends YamlLoader {
static final String RADIO_VALUE = "file"
String yamlFile
FilePath workspace
@Override
Map getContent() {
if(Util.fixEmpty(yamlFile) == null) {
return null
}
Yaml yaml = new Yaml(new SafeConstructor())
InputStream input = createFilePath().read()
try{
yaml.load(input)
} finally {
// NOTE: can not use withCloseable on groovy 1.8.9 (Jenkins included version)
input.close()
}
}
private FilePath createFilePath() {
if (!Util.isRelativePath(yamlFile) || workspace == null) {
return new FilePath(new File(yamlFile))
}
new FilePath(workspace, yamlFile)
}
}