Last active
June 27, 2022 06:48
-
-
Save techdecline/24ebc99a0fa4d25b6c8527ac8414412b to your computer and use it in GitHub Desktop.
Create Git Credential Manager Plaintext Credential File (for Azure Devops)
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
| param ( | |
| [String]$OrganizationName = $($Env:SYSTEM_COLLECTIONURI -replace ".$") , | |
| [String]$UserName = "[email protected]", # this is just a dummy value | |
| [String]$PAT = $Env:SYSTEM_ACCESSTOKEN, | |
| [String]$StorePath = $PWD | |
| ) | |
| # git config | |
| . git config --global credential.interactive false | |
| . git config --global credential.credentialStore plaintext | |
| . git config --global credential.plaintextStorePath $StorePath | |
| . git config --global credential.azreposCredentialType pat | |
| $sb = [System.Text.StringBuilder]::new() | |
| [void]$sb.AppendLine( $PAT ) | |
| [void]$sb.AppendLine( "service=$OrganizationName" ) | |
| [void]$sb.AppendLine( "account=$UserName" ) | |
| $gcmPlaintextPath = Join-Path -Path $StorePath -ChildPath "git/https/dev.azure.com/$(($OrganizationName -split "/")[-1])/$UserName.credential" | |
| $null = New-Item $gcmPlaintextPath -Force | |
| $null = Set-Content -Path $gcmPlaintextPath -Value $sb.ToString() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment