1

We are trying to execute this az devops service-endpoint list in a powershell script added in a pipeline in yaml from Azure DevOps

$SubscriptionId = az devops service-endpoint list --organization "https://dev.azure.com/xxxxx" --project $ProjectName --query "[?data.subscriptionName==$SubscriptionName].data.subscriptionId" -o tsv

For executing the command above, The logs tell that we need to login using az devops login --organization https://dev.azure.com/xxxx/ , how do we do this in the pipeline?

Also we use the system access token variable for logging in like this:

$env:AZURE_DEVOPS_EXT_PAT = $env:SYSTEM_ACCESSTOKEN
1
  • Try Azure CLI task. You would be able to pass a service connection as input to this task. You also don't need to do az login separately if you use this task. Commented Jan 5, 2022 at 15:38

1 Answer 1

1

Thank you Tejas Nagchandi. Posting your suggestion as an answer so that it will be helpful for other community members as well who is facing similar kind of issues.

Below is the sample code of Azure CLI task and try to use that by which you can pass a service connection as input and with the help of this task no need to use az-login as well.

- task: AzureCLI@2
  displayName: Azure CLI
  inputs:
    azureSubscription: <Name of the Azure Resource Manager service connection>
    scriptType: ps
    scriptLocation: inlineScript
    inlineScript: |
      az --version
      az account show

for further details check the Azure CLI task documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.