繁体   English   中英

Azure Devops:Invoke-RestMethod:在控制台中抑制响应但存储在变量中

[英]Azure Devops: Invoke-RestMethod : Response suppressed in console but stored in variable

As part of Azure devops pipeline, I need hit the API to get the Oauth token and use it in the subsequent steps, I was able to achieve this, the only problem is the Oauth is displayed in the devops console, which I want to suppress它,有没有办法可以将 Invoke-RestMethod 的 output 或 pipe 抑制为变量? 我试过了| Out-Null 但这也没有将响应存储在变量中。

提前致谢。 干杯。

$response = Invoke-RestMethod 'https://login.microsoftonline.com/xyz/oauth2/v2.0/token' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
$token=$response.access_token

糟糕,我错过了 not,它没有存储变量。 我找到了另一种无需写入控制台的方法。

Invoke-RestMethod 'https://login.microsoftonline.com/xyz/oauth2/v2.0/token' -Method 'POST' -Headers $headers -Body $body | ForEach-Object {
                      $token=$_.access_token
                      Write-Host "##vso[task.setvariable variable=bearerToken;issecret=true]$token"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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