简体   繁体   English

在Azure DevOps Pipelines中显示REST API内容

[英]Display REST API content in Azure DevOps Pipelines

Im new to Azure and Postman.我是 Azure 和 Postman 的新用户。

Is there a way to display the content of a (GET)Rest API in Azure DevOPS.有没有办法在 Azure DevOPS 中显示 (GET)Rest API 的内容。 The content should be displayed inside the "Run Cake script" in the Pipeline.内容应该显示在管道中的“Run Cake script”中。

Right now i have this:现在我有这个:

Task("Deploy")
    .IsDependentOn("Pack")
    .Does(() =>
    {
        //Code to print the content of the API packages.
    });

How do i proceed?我该如何进行? Once again, im new to this so i might be missing a lot of information that you need in order to help me.再一次,我对此很陌生,所以我可能会遗漏很多您需要的信息来帮助我。 In that case, let me know: :)在那种情况下,请告诉我::)

I'm not familar with Cake script, there are 2 ways to do authentication for Azure DevOps API.我不熟悉 Cake 脚本,有两种方法可以为 Azure DevOps API 进行身份验证。

  1. Private PAT私有PAT
  2. Environment Variable: System.AccessToken环境变量:System.AccessToken

if you want to call Azure DevOps API in your pipeline, you can conside use System.AccessToken.如果您想在管道中调用 Azure DevOps API,可以考虑使用 System.AccessToken。

Here is Powershell Script for your reference, the field of Authorization is different.这里有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM