Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Get-AzureDevOpsTokenFromGit
- {
- Param
- (
- [Parameter(Mandatory = $true)]
- [string]
- $ProjectPath,
- [Parameter()]
- [string]
- $GitTokenHelperPath = "${env:ProgramFiles}/Git/mingw64/bin/git-credential-manager-core.exe"
- )
- if (-not (Test-Path -Path $GitTokenHelperPath))
- {
- throw "No git credential helper found at '$GetTokenHelperPath'"
- }
- $helperParams =
- @"
- protocol=https
- host=dev.azure.com
- path=$ProjectPath
- "@
- $tokenData = $helperParams | & $GitTokenHelperPath get
- $token = ($tokenData | Select-String -Pattern "^password=.+" | Select-Object -First 1) -split '=' `
- | Select-Object -Last 1
- if (-not $token)
- {
- throw "No password in git credential helper output"
- }
- Write-Output $token
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement