vsteam
vsteam copied to clipboard
Update Single Variable
There is no cmdlet to update/create a single variable in a variable group. I'd like one, please. There is a task to get and save the whole group, but I'm after a one liner. This is not for me, this is for a community of users, so instructing them to write a multiline powershell script would not be elegant.
That said, a cmdlet like this would go against what seems to be the convention in this module, specifically that each cmdlet wraps a single REST API call and the consumers are expected to do the rest.
What's the best path forward?
- Leave this issue here, hope the maintainers implement one
- Implement a cmdlet myself, submit a PR
- Implement a cmdlet, publish in my own module
Please advice.
Hi @sevaa,
Third one is not a very good option when it comes to helping the community :-)
But a while ago we went away from only wrapping one API call. So we already have cmdlets the reuse more basic cmdlets of the same module. So I would suggest the same.
Make a cmdlet for every API call you need if it's not already existing and then make your e.g. Update-VSTeamVariableGroupVariable
(redundant name, but it's an example)
So I looked further and I think you would just wrap the *-VSTeamVariableGroup cmdlets.
#updates a variable and marks it as a secret
Update-VSTeamVariableGroupVariable -Name "var1" -Value "mysecret" -IsSecret
# updates a clear text variable
Update-VSTeamVariableGroupVariable -Name "var1" -Value "val"
#other examples
Add-VSTeamVariableGroupVariable -Name "var1" -Value "val"
Add-VSTeamVariableGroupVariable -Name "var1" -Value "mysecret" -IsSecret
Remove-VSTeamVariableGroupVariable -Name "var1"
Long story short: Go ahead and make a PR
That said, a cmdlet like this would go against what seems to be the convention in this module, specifically that each cmdlet wraps a single REST API call and the consumers are expected to do the rest.
Btw. is this stated somewhere in text? If yes then I need to adjust that!
each cmdlet wraps a single REST API call
is this stated somewhere in text?
I don't think it's ever stated explicitly, but at least at some point, maybe early on, the guiding principle of this module's design seemed to be, well, exactly that.
Understood re: the rest, it's forking time :) I think it'd be a "Set"-type command, since I expect it to either add variable if one doesn't exist, or update the value if it does.
Yes maybe and also setting a variable might be destructive. So, a ShouldProcess
could be a good thing to do.
Explain please.
You can look at a code example here: https://github.com/MethodsAndPractices/vsteam/blob/trunk/Source/Public/Set-VSTeamApproval.ps1
Any cmdlet using "Set" should implement the "ShouldProcess". Because "Set" is something like doing a setting. This is also activated when we run "PSScriptAnalyzer" which states this.
More Info:
- https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/useshouldprocessforstatechangingfunctions?view=ps-modules
- https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/required-development-guidelines?view=powershell-7.1#support-confirmation-requests-rd04
- https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-shouldprocess?view=powershell-7.1
Done, see PR #495. No support for secret vars, though.
Hello, are any maintainers reading this? PR #495 is (I think) ready.