mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-19 19:44:27 +02:00
feat: allow passing values to writePipelineEnv (#5270)
This commit is contained in:
parent
e81f901a77
commit
f376166c7f
@ -6,20 +6,23 @@ import groovy.transform.Field
|
||||
void call(Map parameters = [:]) {
|
||||
final script = checkScript(this, parameters) ?: this
|
||||
String piperGoPath = parameters?.piperGoPath ?: './piper'
|
||||
Map cpe = script?.commonPipelineEnvironment?.getCPEMap(script)
|
||||
if (cpe == null) {
|
||||
return
|
||||
String command = "${piperGoPath} writePipelineEnv"
|
||||
|
||||
if (parameters.value) {
|
||||
command += " --value '${parameters.value}'"
|
||||
}
|
||||
Map cpe = script?.commonPipelineEnvironment?.getCPEMap(script)
|
||||
if (cpe == null) return
|
||||
|
||||
def jsonMap = groovy.json.JsonOutput.toJson(cpe)
|
||||
if (piperGoPath && jsonMap) {
|
||||
withEnv(["PIPER_pipelineEnv=${jsonMap}"]) {
|
||||
def output = script.sh(returnStdout: true, script: "${piperGoPath} writePipelineEnv")
|
||||
if (parameters?.verbose) {
|
||||
script.echo("wrote commonPipelineEnvironment: ${output}")
|
||||
}
|
||||
if (!jsonMap) {
|
||||
script.echo("can't write pipelineEnvironment: empty environment")
|
||||
return
|
||||
}
|
||||
withEnv(["PIPER_pipelineEnv=${jsonMap}"]) {
|
||||
def output = script.sh(returnStdout: true, script: command)
|
||||
if (parameters?.verbose) {
|
||||
script.echo("wrote commonPipelineEnvironment: ${output}")
|
||||
}
|
||||
} else {
|
||||
script.echo("can't write pipelineEnvironment: piperGoPath: ${piperGoPath} piperEnvironment ${jsonMap}")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user