Skip to content

Instantly share code, notes, and snippets.

@techdecline
Last active June 27, 2022 06:48
Show Gist options
  • Select an option

  • Save techdecline/24ebc99a0fa4d25b6c8527ac8414412b to your computer and use it in GitHub Desktop.

Select an option

Save techdecline/24ebc99a0fa4d25b6c8527ac8414412b to your computer and use it in GitHub Desktop.
Create Git Credential Manager Plaintext Credential File (for Azure Devops)
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