简体   繁体   中英

Can we save the output in cmd into txt file or environment variables

I want save the output from cmd prompt to text file or environment variables.

For Ex In cmd prompt I executed

az account get-access-token 

The output will be

{"access-token" : token,
 "expiresOn" :
 "Subscription" :
 "Teant" :
 "tokenType" : }

How to save the this dict into any file or can we save access-token into environment variable or how to extract the access-token in cmd prompt

I am trying to implement this method in devops pipeline. Any idea how can I reuse the Only access-token in same script in azure cli or set an pipeline variable and reuse it

this my script

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

So In bash script the first command will be az account get-access-token

from this I will get the dict, so in the command will be request Post in this how to pass access-token where the management-token is there in the same script

Try using the logging command to set the pipeline variable. See Set variables in scripts for details.

You can run az account get-access-token --query accessToken --output json to get the accessToken and set the value to a variable. After that, you can use the variable in the subsequent tasks in pipeline.

The following yaml file for your reference:

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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