vsteam icon indicating copy to clipboard operation
vsteam copied to clipboard

Update Single Variable

Open sevaa opened this issue 2 years ago • 6 comments

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?

  1. Leave this issue here, hope the maintainers implement one
  2. Implement a cmdlet myself, submit a PR
  3. Implement a cmdlet, publish in my own module

Please advice.

sevaa avatar Oct 22 '21 14:10 sevaa

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

SebastianSchuetze avatar Oct 22 '21 14:10 SebastianSchuetze

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!

SebastianSchuetze avatar Oct 22 '21 14:10 SebastianSchuetze

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.

sevaa avatar Oct 22 '21 17:10 sevaa

Yes maybe and also setting a variable might be destructive. So, a ShouldProcess could be a good thing to do.

SebastianSchuetze avatar Oct 22 '21 18:10 SebastianSchuetze

Explain please.

sevaa avatar Oct 23 '21 00:10 sevaa

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

SebastianSchuetze avatar Oct 23 '21 08:10 SebastianSchuetze

Done, see PR #495. No support for secret vars, though.

sevaa avatar Nov 09 '22 17:11 sevaa

Hello, are any maintainers reading this? PR #495 is (I think) ready.

sevaa avatar Jan 09 '23 17:01 sevaa