Skip to content

Commit f376166

Browse files
authored
feat: allow passing values to writePipelineEnv (#5270)
1 parent e81f901 commit f376166

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

vars/writePipelineEnv.groovy

+14-11
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@ import groovy.transform.Field
66
void call(Map parameters = [:]) {
77
final script = checkScript(this, parameters) ?: this
88
String piperGoPath = parameters?.piperGoPath ?: './piper'
9-
Map cpe = script?.commonPipelineEnvironment?.getCPEMap(script)
10-
if (cpe == null) {
11-
return
9+
String command = "${piperGoPath} writePipelineEnv"
10+
11+
if (parameters.value) {
12+
command += " --value '${parameters.value}'"
1213
}
14+
Map cpe = script?.commonPipelineEnvironment?.getCPEMap(script)
15+
if (cpe == null) return
1316

1417
def jsonMap = groovy.json.JsonOutput.toJson(cpe)
15-
if (piperGoPath && jsonMap) {
16-
withEnv(["PIPER_pipelineEnv=${jsonMap}"]) {
17-
def output = script.sh(returnStdout: true, script: "${piperGoPath} writePipelineEnv")
18-
if (parameters?.verbose) {
19-
script.echo("wrote commonPipelineEnvironment: ${output}")
20-
}
18+
if (!jsonMap) {
19+
script.echo("can't write pipelineEnvironment: empty environment")
20+
return
21+
}
22+
withEnv(["PIPER_pipelineEnv=${jsonMap}"]) {
23+
def output = script.sh(returnStdout: true, script: command)
24+
if (parameters?.verbose) {
25+
script.echo("wrote commonPipelineEnvironment: ${output}")
2126
}
22-
} else {
23-
script.echo("can't write pipelineEnvironment: piperGoPath: ${piperGoPath} piperEnvironment ${jsonMap}")
2427
}
2528
}

0 commit comments

Comments
 (0)