Azure-devops-cli-extension: az pipelines ignores default organization when running commands from a local ADO git folder

Created on 6 Oct 2019  路  10Comments  路  Source: Azure/azure-devops-cli-extension

Describe the bug
When running az cli devops commands from an ADO git folder the az cli devops defaults are ignored.

To Reproduce
Azure Cli Version:
2.0.73

Azure-Devops extension version:
0.13.0

Steps to reproduce the behaviour:

  1. Clone an ADO Repo (it's important that's an ADO repo, with other GIT providers the bug doesn't happen)
  2. Navigate to the cloned folder (important, you have to be in the cloned folder)
  3. Login with az devops loginand provide a token (my token has all the scopes)
  4. Set defaults, like : az devops configure --defaults organization=https://dev.azure.com/contoso project=ContosoWebApp
  5. Run a command without providing the --organization switch: az pipelines pool list

ERROR:

The requested resource requires user authentication: https://@dev.azure.com//azure%20platform%20team/_git/azure%20platform%20team/vsts/info

Note: the * is just to keep my stuff private.

Expected behavior
The normal run of the command

Additional context

  • Running the command outside the Git Folder works perfectly.
  • Running the command inside the cloned Git folder of another provider (like GitHub etc..) works perfectly
  • To make it work inside the Git Folder I have to explicitly provide the --organization switch
question

All 10 comments

@olandese This is the expected behavior today. You can use the detect flag to set avoid this behavior by setting it to false.
--detect false

Reason: In most cases when a user is running a command from within a git repo the intention is that commands are targeted at the same organization and project to which this repo belongs.
The defaults work anywhere when the command is invoked from outside a ADO git repo.

This has been in place since the initial release itself. In most cases these two things help users who are using the CLI for interactive purposes.

For automation use cases it is always suggested to explicitly use --organization -- project parameters to have consistent behavior of automation scripts.

So the order of detection is -

  1. Explicit params --org --project
  2. Detect from local repo (if --detect is on, which is by default)
  3. Use defaults

Please let know if that helps. I will be closing the issue.

@olandese This is the expected behavior today. You can use the detect flag to set avoid this behavior by setting it to false.
--detect false

Reason: In most cases when a user is running a command from within a git repo the intention is that commands are targeted at the same organization and project to which this repo belongs.
The defaults work anywhere when the command is invoked from outside a ADO git repo.

This has been in place since the initial release itself. In most cases these two things help users who are using the CLI for interactive purposes.

For automation use cases it is always suggested to explicitly use --organization -- project parameters to have consistent behavior of automation scripts.

So the order of detection is -

  1. Explicit params --org --project
  2. Detect from local repo (if --detect is on, which is by default)
  3. Use defaults

Please let know if that helps. I will be closing the issue.

Thank you for the good explanation!
I think this flow order should be better documented :)

@geverghe Please see if some documentation change is needed.

Hey @olandese - thank you for raising the documentation concern. To ensure we meet your expectation and prioritize accordingly, could you tell me how you learnt about the command functioning? From docs.microsoft.com or from the command help text?

I learned from both.
But I would expect the flow described above by @atbagga somewhere in the Getting started documentation ( https://docs.microsoft.com/en-us/azure/devops/cli/get-started?view=azure-devops )

Got it - thanks for the confirmation. 馃憤

Hey @olandese - I have included the documentation here - https://docs.microsoft.com/en-us/azure/devops/cli/auto-detect-and-git-aliases?view=azure-devops#parameter-hierarchy. This is the portion where we explain about auto detect concept and thought it would be the best place to include the details pertaining to parameter priority as well. I am closing this issue.

Great work! thank you for listening :)

@geverghe could you also add the note to the Getting Started Guide. This was where I first learned about setting default config

@geverghe I ran into the same issue and also used the Getting started guide @mydiemho did, so I second their suggestion.

Was this page helpful?
0 / 5 - 0 ratings