[英]Can we save the output in cmd into txt file or environment variables
我想將 output 從 cmd 提示保存到文本文件或環境變量。
對於 Ex In cmd 提示我執行
az account get-access-token
output 將是
{"access-token" : token,
"expiresOn" :
"Subscription" :
"Teant" :
"tokenType" : }
如何將此字典保存到任何文件中,或者我們可以將訪問令牌保存到環境變量中,或者如何在 cmd 提示符中提取訪問令牌
我正在嘗試在 devops 管道中實現此方法。 知道如何在 azure cli 的同一腳本中重用 Only access-token 或設置管道變量並重用它
這是我的腳本
curl --netrc --request POST \
https://<databricks-instance>/api/2.0/secrets/scopes/create \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <token>" \
--header "X-Databricks-Azure-SP-Management-Token: <management-token>" \
--data @create-scope.json
所以在 bash 腳本中,第一個命令是az account get-access-token
從這里我會得到字典,所以在命令中將是 request Post in this how to pass access-token where the management-token is there in the same script
嘗試使用 logging 命令設置管道變量。 有關詳細信息,請參閱在腳本中設置變量。
您可以運行az account get-access-token --query accessToken --output json
來獲取accessToken
並將值設置為變量。 之后,您可以在管道中的后續任務中使用該變量。
以下 yaml 文件供您參考:
steps:
- task: AzureCLI@2
displayName: 'Azure CLI '
inputs:
azureSubscription: 'service-connection'
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
$accessToken = az account get-access-token --query accessToken --output json
Write-Host "##vso[task.setvariable variable=Token]$accessToken "
- powershell: |
# Write your PowerShell commands here.
Write-Host "SecretToken" $(Token)
displayName: 'Test the variable'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.