1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-27 21:49:15 +02:00

feat: allow passing values to writePipelineEnv (#5261)

This commit is contained in:
phgermanov 2025-02-11 11:37:57 +02:00 committed by GitHub
parent 8895891860
commit ed2381bc51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,20 +6,27 @@ 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}")
}
}
} else {
script.echo("can't write pipelineEnvironment: piperGoPath: ${piperGoPath} piperEnvironment ${jsonMap}")
if (!jsonMap) {
script.echo("can't write pipelineEnvironment: empty environment")
return
}
withEnv(["PIPER_pipelineEnv=${jsonMap}"]) {
executeCommand(script, command, parameters?.verbose)
}
}
private void executeCommand(script, String command, boolean verbose) {
def output = script.sh(returnStdout: true, script: command)
if (verbose) {
script.echo("wrote commonPipelineEnvironment: ${output}")
}
}