Azure devops REST API |内部版本号提取到txt文件



我正试图通过POWERSHELL将一个内部版本号提取到TXT文件中,我收到了GET请求,并安排了URI。

我有一个PAT TOKEN格式,但我做不到,如何对TXT文件执行OutFile?

# Build Auth header
$MyPat = "XXXX"
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$MyPat"))
$h = @{'Authorization' = 'Basic ' + $B64Pat}
$BuildNumberInfo = Invoke-WebRequest -Uri "https://dev.azure.com/$($Company)/$($Project)/_apis/build/builds/$($BuildID)?api-version=6.0-preview.6" -Method 'GET' 

使用Invoke-RestMethod而不是Invoke-WebRequest:

# Build Auth header
$MyPat = "XXX"
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$MyPat"))
$h = @{'Authorization' = 'Basic ' + $B64Pat}
$BuildNumberInfo = Invoke-RestMethod -Uri "https://dev.azure.com/$($Company)/$($Project)/_apis/build/builds/$($BuildID)?api-version=6.0-preview.6" -Method 'GET' -Headers $h
$BuildNumberInfo.buildNumber | Out-File buildnumber.txt

相关内容

  • 没有找到相关文章