File tree Expand file tree Collapse file tree
docs/preview/03-Features/powershell
Arcus.Scripting.Tests.Unit Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,16 +18,26 @@ PS> Install-Module -Name Arcus.Scripting.DevOps -Repository PSGallery -AllowClob
1818
1919Assign a value to a DevOps pipeline variable during the execution of this pipeline.
2020
21- | Parameter | Mandatory | Description |
22- | --------------- | --------- | ------------------------------------------------- |
23- | ` Name ` | yes | The name of the variable to set in the pipeline |
24- | ` Value ` | yes | The value of the variable to set in the pipeline |
21+ | Parameter | Mandatory | Description |
22+ | --------------------- | --------- | ------------------------------------------------- |
23+ | ` Name ` | yes | The name of the variable to set in the pipeline |
24+ | ` Value ` | yes | The value of the variable to set in the pipeline |
25+ | ` AsSecret ` | no | The switch to set the variable as a secret |
2526
2627** Example**
2728
29+ Setting a variable:
30+
2831``` powershell
2932PS> Set-AzDevOpsVariable "my-variable" "my-variable-value"
30- # #vso[task.setvariable variable=my-variable] my-variable-value
33+ ##vso[task.setvariable variable=my-variable] my-variable-value
34+ ```
35+
36+ Setting a variable as a secret:
37+
38+ ``` powershell
39+ PS> Set-AzDevOpsVariable "my-variable" "my-variable-value" -AsSecret
40+ ##vso[task.setvariable variable=my-variable;issecret=true] ***
3141```
3242
3343## Setting ARM outputs to Azure DevOps variable group
Original file line number Diff line number Diff line change 1414function Set-AzDevOpsVariable {
1515 param (
1616 [parameter (Mandatory = $true )][string ] $Name = $ (throw " Name is required" ),
17- [parameter (Mandatory = $true )][string ] $Value = $ (throw " Value is required" )
17+ [parameter (Mandatory = $true )][string ] $Value = $ (throw " Value is required" ),
18+ [parameter (Mandatory = $false )][switch ] $AsSecret = $false
1819 )
1920
20- Write-Host " #vso[task.setvariable variable=$Name ] $Value "
21+ if ($AsSecret ) {
22+ Write-Host " ##vso[task.setvariable variable=$Name ;issecret=true] $Value "
23+ } else {
24+ Write-Host " ##vso[task.setvariable variable=$Name ] $Value "
25+ }
2126}
2227
2328Export-ModuleMember - Function Set-AzDevOpsVariable
Original file line number Diff line number Diff line change @@ -5,14 +5,24 @@ InModuleScope Arcus.Scripting.DevOps {
55 Context " Setting ARM outputs to Azure DevOps variable group" {
66 It " Setting DevOps variable should write to host" {
77 # Arrange
8- Mock Write-Host { $Object | Should - Be " #vso[task.setvariable variable=test] value" } - Verifiable
8+ Mock Write-Host { $Object | Should - Be " ## vso[task.setvariable variable=test] value" } - Verifiable
99
1010 # Act
1111 Set-AzDevOpsVariable " test" " value"
1212
1313 # Assert
1414 Assert-VerifiableMock
1515 }
16+ It " Setting DevOps variable as secret should write to host" {
17+ # Arrange
18+ Mock Write-Host { $Object | Should - Be " ##vso[task.setvariable variable=test;issecret=true] value" } - Verifiable
19+
20+ # Act
21+ Set-AzDevOpsVariable " test" " value" - AsSecret
22+
23+ # Assert
24+ Assert-VerifiableMock
25+ }
1626 It " Setting DevOps variable group from ARM outputs should send info to DevOps project" {
1727 # Arrange
1828 $variableGroupName = " some-variable-group-name"
You can’t perform that action at this time.
0 commit comments