forked from StartAutomating/PSDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set-ADOVariable.ps1
45 lines (41 loc) · 1.52 KB
/
Set-ADOVariable.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function Set-ADOVariable
{
<#
.Synopsis
Sets an ADO Variable
.Description
Sets a Azure DevOps Variable
.Example
Set-ADOVariable -Name Sauce -Value "Crushed Tomatoes"
.Link
https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "", Justification="Directly outputs in certain scenarios")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification="Confirmation would be impossible within host")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Test-ForUnusableFunction", "", Justification="Directly outputs in certain scenarios")]
[OutputType([string])]
param(
# The variable name.
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[string]
$Name,
# The variable value.
[Parameter(ValueFromPipelineByPropertyName)]
[PSObject]
$Value,
# If set, the variable will be a secret. Secret variables will not echo in logs.
[Alias('IsSafe','Secret')]
[switch]
$IsSecret
)
process {
#region Prepare Output
$out = "##vso[task.setvariable variable=$Name$(if ($IsSecret) {";issecret=true"})]$Value"
#endregion Prepare Output
if ($env:Agent_ID -and $DebugPreference -eq 'SilentlyContinue') {
Write-Host -Object $out
} else {
$out
}
}
}