-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzPipelineVariable.psm1
54 lines (48 loc) · 1.73 KB
/
AzPipelineVariable.psm1
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
46
47
48
49
50
51
52
53
54
<#
.SYNOPSIS
Sets a variable in an Azure Pipelines pipeline.
.DESCRIPTION
The variable is set using the task.setvariable command. It will be read-only
by default.
.EXAMPLE
Set-AzPipelineVariable -Name myVar -Value 'xyz'
.EXAMPLE
Set-AzPipelineVariable secretOutputVar 'xyz' -Secret -Output
.EXAMPLE
Get-Content .\example.json | ConvertFrom-Json | Select-Object -Expand foo | Set-AzPipelineVariable myVar
.LINK
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts
#>
function Set-AzPipelineVariable {
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]
# The name of the variable to set.
$Name,
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[AllowEmptyString()]
[string]
# The value of the variable to set.
$Value,
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
# Makes the variable an output variable.
$Output,
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
# Makes the variable a secret variable.
$Secret,
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
# Makes the variable mutable (not readonly).
$Mutable
)
process {
Write-Host ('##vso[task.setvariable variable={0};isreadonly={1};isoutput={2};issecret={3}]{4}' `
-f $Name, -not $Mutable, $Output, $Secret, $Value)
$valueToLog = if ($Secret) { '***' } else { $Value }
Write-Verbose ("Set variable '{0}' to '{1}'. [readonly={2}; output={3}; secret={4}]" `
-f $Name, $valueToLog, -not $Mutable, $Output, $Secret)
}
}