Skip to content

Commit

Permalink
feat: allow passing values to writePipelineEnv (#5261)
Browse files Browse the repository at this point in the history
  • Loading branch information
phgermanov authored Feb 11, 2025
1 parent 8895891 commit ed2381b
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions vars/writePipelineEnv.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
}

0 comments on commit ed2381b

Please sign in to comment.