[英]Display REST API content in Azure DevOps Pipelines
我是 Azure 和 Postman 的新用戶。
有沒有辦法在 Azure DevOPS 中顯示 (GET)Rest API 的內容。 內容應該顯示在管道中的“Run Cake script”中。
現在我有這個:
Task("Deploy")
.IsDependentOn("Pack")
.Does(() =>
{
//Code to print the content of the API packages.
});
我該如何進行? 再一次,我對此很陌生,所以我可能會遺漏很多您需要的信息來幫助我。 在那種情況下,請告訴我::)
我不熟悉 Cake 腳本,有兩種方法可以為 Azure DevOps API 進行身份驗證。
如果您想在管道中調用 Azure DevOps API,可以考慮使用 System.AccessToken。
這里有Powershell Script供大家參考,Authorization的字段不同。
function Http-Request {
param (
[Parameter(Mandatory=$true)]
[string] $Url,
[Parameter(Mandatory=$false)]
[string] $SystemToken
)
if([string]::IsNullOrEmpty($SystemToken)) {
$pat = 'YOUR_PAT'
$username = 'YOUR_USERNAME'
$auth = '{0}:{1}' -f $username, $pat
$bytes = [System.Text.Encoding]::UTF8.GetBytes($auth)
$encoded = [Convert]::ToBase64String($bytes)
$auth = 'Basic ' + $encoded
} else {
$auth = 'Bearer ' + $SystemToken
}
$headers = @{
'Content-Type' = 'application/json'
'Authorization' = $auth
}
Write-Host -ForegroundColor Green 'Http Request:'$Url
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
$response = Invoke-RestMethod -Uri $Url -Method Get -Headers $headers
Write-Host ($reponse | Format-List | Out-String)
return $response
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.