From ed2381bc51224eb38508adc6a1bc54d848d90479 Mon Sep 17 00:00:00 2001 From: phgermanov Date: Tue, 11 Feb 2025 11:37:57 +0200 Subject: [PATCH] feat: allow passing values to writePipelineEnv (#5261) --- vars/writePipelineEnv.groovy | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/vars/writePipelineEnv.groovy b/vars/writePipelineEnv.groovy index 1b9b3918ae..9049c62fbf 100644 --- a/vars/writePipelineEnv.groovy +++ b/vars/writePipelineEnv.groovy @@ -6,20 +6,27 @@ import groovy.transform.Field void call(Map parameters = [:]) { final script = checkScript(this, parameters) ?: this String piperGoPath = parameters?.piperGoPath ?: './piper' + String command = "${piperGoPath} writePipelineEnv" + + if (parameters.value) { + command += " --value '${parameters.value}'" + } Map cpe = script?.commonPipelineEnvironment?.getCPEMap(script) - if (cpe == null) { + if (cpe == null) return + + def jsonMap = groovy.json.JsonOutput.toJson(cpe) + if (!jsonMap) { + script.echo("can't write pipelineEnvironment: empty environment") return } + withEnv(["PIPER_pipelineEnv=${jsonMap}"]) { + executeCommand(script, command, parameters?.verbose) + } +} - 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}") +private void executeCommand(script, String command, boolean verbose) { + def output = script.sh(returnStdout: true, script: command) + if (verbose) { + script.echo("wrote commonPipelineEnvironment: ${output}") } }