From aeddbf95c5a80ad71a4469a829049d08321997b7 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Tue, 19 Sep 2023 11:21:26 +0200 Subject: [PATCH] Raise variable from enviroment --- vsts-variable-set/v3/task.json | 26 ++++++++++++++++++++++- vsts-variable-set/v3/vsts-variable-set.ts | 23 +++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/vsts-variable-set/v3/task.json b/vsts-variable-set/v3/task.json index bcfd2cf..9bae2c3 100644 --- a/vsts-variable-set/v3/task.json +++ b/vsts-variable-set/v3/task.json @@ -50,6 +50,19 @@ "required": false, "visibleRule": "VariableName=release.releasename" }, + { + "defaultValue": "value", + "helpMarkdown": "Take the value from the input or an environment variable.", + "label": "From", + "name": "From", + "required": true, + "type": "pickList", + "options": { + "value": "value", + "env": "env" + }, + "aliases": ["variableName"] + }, { "defaultValue": "", "helpMarkdown": "The value to assign to the variable.", @@ -57,7 +70,18 @@ "name": "Value", "required": false, "type": "string", - "aliases": ["value"] + "aliases": ["value"], + "visibleRule": "From=value" + }, + { + "defaultValue": "", + "helpMarkdown": "The value to assign to the variable.", + "label": "Environment Variable", + "name": "Env", + "required": true, + "type": "string", + "aliases": ["Env", "Environment"], + "visibleRule": "From=env" }, { "defaultValue": false, diff --git a/vsts-variable-set/v3/vsts-variable-set.ts b/vsts-variable-set/v3/vsts-variable-set.ts index 77ea7b8..85b4a15 100644 --- a/vsts-variable-set/v3/vsts-variable-set.ts +++ b/vsts-variable-set/v3/vsts-variable-set.ts @@ -1,7 +1,28 @@ import * as tl from "azure-pipelines-task-lib/task"; const variable = tl.getInput("VariableName", true); -const value = tl.getInput("Value"); + +function getValue() +{ + const from = tl.getInput("From") || "value"; + switch (from) + { + case "value": + { + return tl.getInput("Value"); + } + case "env": + { + return process.env[tl.getInput("Env", true)]; + } + default: + { + return ""; + } + } +} + +const value = getValue() const isSecret = tl.getBoolInput("isSecret") || false; const useTaskLib = tl.getBoolInput("useTasklib") || false; const useSetVariableForReleaseName = tl.getBoolInput("useSetVariableForReleaseName") || false;