-
Notifications
You must be signed in to change notification settings - Fork 155
Set-VSTeamVariableGroupVariable cmdlet, tests, docs #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SebastianSchuetze
merged 9 commits into
MethodsAndPractices:trunk
from
sevaa:feature_setvar
May 11, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4473a94
Set-VSTeamVariableGroupVariable cmdlet, tests, docs
aeca139
Changelog
b019971
docs: updated changelog
SebastianSchuetze 2fa138d
docs: moved explanation to notes section
SebastianSchuetze db32a76
Set-VSTeamVariableGroupVariable docs update
2c18fd5
Fixes for Set-VSTeamVariableGroupVariable
262e512
Fix for the Update-VSTeamProject test on *nix - same as in PR#494
6ac13f7
build: updated version
SebastianSchuetze 7141252
Merge branch 'trunk' into feature_setvar
SebastianSchuetze File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| <!-- #include "./common/header.md" --> | ||
|
|
||
| # Set-VSTeamVariableGroupVariable | ||
|
|
||
| ## SYNOPSIS | ||
|
|
||
| <!-- #include "./synopsis/Set-VSTeamVariableGroupVariable.md" --> | ||
|
|
||
| ## SYNTAX | ||
|
|
||
| ## DESCRIPTION | ||
|
|
||
| <!-- #include "./synopsis/Set-VSTeamVariableGroupVariable.md" --> | ||
|
|
||
| ## EXAMPLES | ||
|
|
||
| ### Example 1 | ||
|
|
||
| ```powershell | ||
|
|
||
| # In project MyProject, variable group MyVarGroup, set the value of Foo to Hello. The variable | ||
| # called Foo will be created if it doesn't already exist. | ||
|
|
||
| Set-VSTeamVariableGroupVariable -ProjectName MyProject -GroupName MyVarGroup -Name Foo -Value Hello | ||
| ``` | ||
|
|
||
| ## PARAMETERS | ||
|
|
||
| ### GroupName | ||
|
|
||
| Name of the existing variable group | ||
|
|
||
| ```yaml | ||
| Type: String | ||
| Aliases: | ||
|
|
||
| Required: True | ||
| Position: Named | ||
| Default value: None | ||
| Accept pipeline input: True (ByPropertyName) | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### Name | ||
|
|
||
| Name of the variable to set | ||
|
|
||
| ```yaml | ||
| Type: String | ||
| Aliases: | ||
|
|
||
| Required: True | ||
| Position: Named | ||
| Default value: None | ||
| Accept pipeline input: True (ByPropertyName) | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### Value | ||
|
|
||
| The new value of the variable | ||
|
|
||
| ```yaml | ||
| Type: String | ||
| Aliases: | ||
|
|
||
| Required: False | ||
| Position: Named | ||
| Default value: "" | ||
| Accept pipeline input: True (ByPropertyName) | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| <!-- #include "./params/projectName.md" --> | ||
|
|
||
| ## INPUTS | ||
|
|
||
| ## OUTPUTS | ||
|
|
||
| ## NOTES | ||
|
|
||
| Secret variable updating or creation is not currently supported. | ||
|
|
||
| <!-- #include "./common/prerequisites.md" --> | ||
|
|
||
| ## RELATED LINKS | ||
|
|
||
|
|
||
|
|
||
| [Add-VSTeamVariableGroup](Add-VSTeamVariableGroup.md) | ||
|
|
||
| [Get-VSTeamVariableGroup](Get-VSTeamVariableGroup.md) | ||
|
|
||
| [Remove-VSTeamVariableGroup](Remove-VSTeamVariableGroup.md) | ||
|
|
||
| [Update-VSTeamVariableGroup](Update-VSTeamVariableGroup.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Adds a variable to an existing variable group, or changes its value if the variable is already present. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| function Set-VSTeamVariableGroupVariable { | ||
| [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "Medium", | ||
| HelpUri='https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Set-VSTeamVariableGroupVariable')] | ||
| param( | ||
| [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] | ||
| [string] $GroupName, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string] $Name, | ||
|
|
||
| [string] $Value, | ||
|
|
||
| [switch] $Force, | ||
|
|
||
| [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] | ||
| [vsteam_lib.ProjectValidateAttribute($false)] | ||
| [ArgumentCompleter([vsteam_lib.ProjectCompleter])] | ||
| [string] $ProjectName | ||
| ) | ||
|
|
||
| process { | ||
| if ($Force -or $pscmdlet.ShouldProcess("$GroupName.$Name", "Set Variable Value")) { | ||
| try { | ||
| $gl = Get-VSTeamVariableGroup -ProjectName $ProjectName | ||
| # Exception if a group with a name is not found is not particularly descriptive | ||
| $g = $gl | Where-Object -FilterScript {$_.Name -eq $GroupName} | ||
| if($g) { | ||
| if($g.variables | Get-Member -Name $Name) { | ||
| if(($g.variables.$Name | Get-Member -Name isSecret) -and $g.variables.$Name.isSecret) { | ||
| Write-Error "The variable $Name is a secret one. Updating secret variables is not currently supported." | ||
sevaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return | ||
| } | ||
| else { | ||
| $g.variables.$Name.value = $Value | ||
| } | ||
| } | ||
| else { | ||
| Add-Member -InputObject $g.variables -MemberType NoteProperty -Name $Name -Value ([pscustomobject]@{value=$Value}) | ||
| } | ||
| $body = $g | ConvertTo-Json -Depth 20 -Compress | ||
| Update-VSTeamVariableGroup -ProjectName $ProjectName -Id $g.Id -Body $body -Force | Out-Null | ||
| } | ||
| else { | ||
| Write-Error "Group $GroupName was not found." | ||
| return | ||
| } | ||
| } | ||
| catch { | ||
| _handleException $_ | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Tests/function/tests/Set-VSTeamVariableGroupVariable.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| Set-StrictMode -Version Latest | ||
|
|
||
| Describe 'VSTeamVariableGroup' { | ||
| BeforeAll { | ||
| . "$PSScriptRoot\_testInitialize.ps1" $PSCommandPath | ||
| } | ||
|
|
||
| Context 'Set-VSTeamVariableGroupVariable' { | ||
| Context 'Services' { | ||
| BeforeAll { | ||
| Mock _getApiVersion { return 'VSTS' } | ||
| Mock _getInstance { return 'https://dev.azure.com/test' } | ||
| Mock Get-VSTeamVariableGroup { @(@{ | ||
| name = "TheGroup"; | ||
| id = 101; | ||
| variables = @{ | ||
| "x" = @{value="A"}; | ||
| "y" = @{value="B"}; | ||
| "s" = @{value=$null; isSecret=$True} | ||
| } | ||
| }) | ConvertTo-JSON | ConvertFrom-JSON} | ||
sevaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Mock _getApiVersion { return '5.0-preview.1-unitTests' } -ParameterFilter { $Service -eq 'VariableGroups' } | ||
| Mock Update-VSTeamVariableGroup {} | ||
| Mock Write-Error {} | ||
| } | ||
|
|
||
| It 'should change the value of an exisiting variable' { | ||
| Set-VSTeamVariableGroupVariable -ProjectName project -GroupName TheGroup -Name x -Value NewValue -Force | ||
|
|
||
| Should -Invoke Update-VSTeamVariableGroup -Exactly -Scope It -Times 1 -ParameterFilter { | ||
| ($Body | ConvertFrom-JSON).variables.x.value -eq "NewValue" | ||
| } | ||
| } | ||
|
|
||
| It 'should create a new variable' { | ||
| Set-VSTeamVariableGroupVariable -ProjectName project -GroupName TheGroup -Name z -Value ANewOne -Force | ||
|
|
||
| Should -Invoke Update-VSTeamVariableGroup -Exactly -Scope It -Times 1 -ParameterFilter { | ||
| ($Body | ConvertFrom-JSON).variables.z.value -eq "ANewOne" | ||
| } | ||
| } | ||
|
|
||
| It 'should fail on nonexistent group' { | ||
| Set-VSTeamVariableGroupVariable -ProjectName project -GroupName NotAGroup -Name z -Value ANewOne -Force | ||
| Should -Invoke Write-Error -Exactly -Scope It -Times 1 | ||
| } | ||
|
|
||
| It 'should fail on a secret var' { | ||
| Set-VSTeamVariableGroupVariable -ProjectName project -GroupName TheGroup -Name s -Value NewValue -Force | ||
| Should -Invoke Write-Error -Exactly -Scope It -Times 1 | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.