Closed mnieto closed 1 year ago
I think the problem was introduced in commit 0528c76 due #467 and closed with #480
While loading the module, if there is a default project, it executes Set-VSTeamAccount -Account $env:TEAM_ACCT -PersonalAccessToken $env:TEAM_PAT
But:
$env:TEAM_PAT
already has been base64 encoded during the previous Set-VSTeamAccount
. Set-VSTeamAccount
was called with -UserBearerToken, it will fail to initialize because the variable $env:TEAM_PAT
is not setI managed to make it work with
# set vsteam account to initialize given variables properly
$pat = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($env:TEAM_PAT)) #decode base64 stored pat
$pat = $pat.Substring(1) #remove the leading :
$defaultProject = $env:TEAM_PROJECT #save temporary defalt project because is removed during Set-VSTeamAccount call
Set-VSTeamAccount -Account $env:TEAM_ACCT -PersonalAccessToken $pat -Version $env:TEAM_VERSION
# Make sure the value in the environment variable still exisits.
if (Get-VSTeamProject | Where-Object ProjectName -eq $defaultProject) {
Set-VSTeamDefaultProject -Project $defaultProject
}
else {
Write-Warning "The default project '$defaultProject' stored in the environment variable TEAM_PROJECT does not exist."
}
but still not resolved the issue that security was configured with -UserBearerToken parameter instead -PersonalAccessToken
What's the best way to get this resolved? I'm currently working around this by adding the following to my PowerShell profile after importing the VSTeam module:
Set-VSTeamAccount -Account 'Foo' -Level 'User' -SecurePersonalAccessToken $securePAT
Set-VSTeamDefaultProject -Project 'Bar' -Level 'User'
Much thanks for @mnieto for identifying the issue and creating pull request https://github.com/MethodsAndPractices/vsteam/pull/508!
Steps to reproduce
Once configured the module with Set-VSTeamAccount:
If we close the powersell session and open a new one:
output
Then, import the module and test the env variables:
output now is:
We lost the version, default project and TEAM_PAT has changed Because the last one, we cannot connect to azure services and we need to run
Set-VSTeamAccount
in each new powershell sessionExpected behavior
Configuration is recovered from previous sessions
Actual behavior?
TEAM_PAT has change and default project name and Version are lost
We cannot connect to azure services and we need to run
Set-VSTeamAccount
in each new powershell sessionThis happen in version 7.9.0
On Which OS have you tried it?
Windows
What was your server version?
Azure DevOps Services
Other server version
No response
Log output of used API
Log output of $PSVersionTable