question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] az devops login using PAT fails if organization is not specified.

See original GitHub issue

Describe the bug We currently use the extension to automatically raise Pull Requests during a YAML build process. The recent release of 0.14.0 has now caused our builds to fail during the listing and creation of Pull Requests (az repos pr list and az repos pr create). We have reverted to version 0.13.0 of the extension that seems to resolve the issue.

To Reproduce Azure Cli Version: azure-cli (2.0.76)

Azure-Devops extension version: azure-devops (0.14.0)

Steps to reproduce the behavior:

  1. Login using echo ${AZURE_DEVOPS_EXT_PAT} | sudo az devops login
  2. Setup organization and project sudo az devops configure --defaults organization=${{ parameters.devops_org }} project=${{ parameters.devops_project }} --use-git-aliases true
  3. Run sudo az repos pr list
  4. See error -
DEBUG: Getting credential: azdevops-cli:https://<org-name>@dev.azure.com/<org-name>
DEBUG: Getting credential: azdevops-cli: default
DEBUG: handling generic error
ERROR: cli.azure.cli.core.util : Before you can run Azure DevOps commands, you need to run the login command(az login if using AAD/MSA identity else az devops login if using PAT token) to setup credentials.  Please see https://aka.ms/azure-devops-cli-auth for more information.
ERROR: Before you can run Azure DevOps commands, you need to run the login command(az login if using AAD/MSA identity else az devops login if using PAT token) to setup credentials.  Please see https://aka.ms/azure-devops-cli-auth for more information.
INFO: az_command_data_logger : exit code: 1
INFO: Suppress exception There are no active accounts.
INFO: Suppress exception Please run 'az login' to setup account.

Expected behavior The existing Pull Requests would be listed in the output window

Debug logs With 0.14.0

DEBUG: Event: CommandInvoker.OnPostArgumentLoad []
DEBUG: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x7f2fccb77950>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x7f2fccb77ae8>]
DEBUG: Event: CommandInvoker.OnCommandTableLoaded []
DEBUG: Event: CommandInvoker.OnPreParseArgs [<function _documentdb_deprecate at 0x7f2fca9bf840>]
DEBUG: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7f2fcce75bf8>, <function CLIQuery.handle_query_parameter at 0x7f2fccea1c80>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x7f2fccb779d8>, <function handler at 0x7f2fca884ae8>, <function DevCommandsLoader.post_parse_args at 0x7f2fca0176a8>]
DEBUG: Extensions directory: '/root/.azure/cliextensions'
DEBUG: Extensions directory: '/root/.azure/cliextensions'
INFO: az_command_data_logger : extension name: azure-devops
INFO: az_command_data_logger : extension version: 0.14.0
DEBUG: No tty available.
INFO: Getting PAT token in non-interactive mode.
DEBUG: Event: CommandInvoker.OnTransformResult [<function _resource_group_transform at 0x7f2fccb6f378>, <function _x509_from_base64_to_hex_transform at 0x7f2fccb6f400>]
DEBUG: Event: CommandInvoker.OnFilterResult []
DEBUG: Event: Cli.PostExecute []
INFO: az_command_data_logger : exit code: 0
INFO: Suppress exception There are no active accounts.
INFO: Suppress exception Please run 'az login' to setup account.
INFO: telemetry.save : Save telemetry record of length 2379 in cache
WARNING: telemetry.check : Negative: The /root/.azure/telemetry.txt was modified at 2019-11-12 11:30:15.434606, which in less than 600.000000 s
INFO: command ran in 0.379 seconds.
##[debug]Exit code 0 received from tool '/bin/bash'
##[debug]STDIO streams have closed for tool '/bin/bash'
##[debug]task result: Succeeded
##[debug]Processed: ##vso[task.complete result=Succeeded;done=true;]
##[debug]Handler exit code: 0
Finishing: Login Azure DevOps Extension

With 0.13.0 It goes into Keyring to save the PAT

DEBUG: Loaded module 'storage' in 0.030 seconds.
DEBUG: Loaded module 'vm' in 0.015 seconds.
DEBUG: Loaded all modules in 0.258 seconds. (note: there's always an overhead with the first module loaded)
DEBUG: Extensions directory: '/root/.azure/cliextensions'
DEBUG: Found 1 extensions: ['azure-devops']
DEBUG: Extensions directory: '/root/.azure/cliextensions'
DEBUG: Extension compatibility result: is_compatible=True cli_core_version=2.0.76 min_required=2.0.69 max_required=None
DEBUG: Extensions directory: '/root/.azure/cliextensions'
DEBUG: Loaded extension 'azure-devops' in 0.022 seconds.
DEBUG: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7f4e01d4be18>]
INFO: az_command_data_logger : command args: devops login --debug
DEBUG: metadata file logging enabled - writing logs to '/root/.azure/commands'.
DEBUG: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x7f4e01cebd90>]
DEBUG: Event: CommandInvoker.OnPostArgumentLoad []
DEBUG: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x7f4e01ca3950>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x7f4e01ca3ae8>]
DEBUG: Event: CommandInvoker.OnCommandTableLoaded []
DEBUG: Event: CommandInvoker.OnPreParseArgs [<function _documentdb_deprecate at 0x7f4dffaeb840>]
DEBUG: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7f4e01fa4bf8>, <function CLIQuery.handle_query_parameter at 0x7f4e01fcdc80>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x7f4e01ca39d8>, <function handler at 0x7f4dff9afae8>, <function DevCommandsLoader.post_parse_args at 0x7f4dff1436a8>]
DEBUG: Extensions directory: '/root/.azure/cliextensions'
DEBUG: Extensions directory: '/root/.azure/cliextensions'
INFO: az_command_data_logger : extension name: azure-devops
INFO: az_command_data_logger : extension version: 0.13.0
DEBUG: No tty available.
INFO: Getting PAT token in non-interactive mode.
DEBUG: installing keyring~=17.1.1
DEBUG: Running: ['/opt/az/bin/python3', '-m', 'pip', 'install', 'keyring~=17.1.1', '--target', '/root/.azure/cliextensions/azure-devops', '-vv', '--disable-pip-version-check', '--no-cache-dir']
DEBUG: Collecting keyring~=17.1.1

Additional context I think this is caused by https://github.com/Azure/azure-devops-cli-extension/commit/17a52c3f266b6bbcd8fbe13210a291897f4cd80f#diff-75719292666380669eaa08dc8e285e5c Looks like the try-expect block now only runs when if organization is not None: evaluates to true. Previously set_credential(organization=organization, token=token) _check_and_set_default_organization(organization) would run outside of the if block.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
atbaggacommented, Nov 13, 2019

@liamehenderson Thanks for reporting the issue in detail! We will fix it ASAP.

0reactions
Lddeivacommented, Jun 8, 2021

@atbagga,

The error remains same when I use the command $PAT | az devops login --org $org.

Error screeshot:- image

Agent details:- image

Read more comments on GitHub >

github_iconTop Results From Across the Web

az devops login errors when logging in using PAT token
Failed to store PAT using keyring; falling back to file storage. You can clear the stored credential by running az devops logout. Refer...
Read more >
az devops login Failed to store PAT using keyring; falling back ...
When you are using az devops login command, first make sure you are using Azure DevOps Service organization URL.
Read more >
Unable to run az devops login from a bash script - Microsoft Q&A
I have my azure-pipelines.yaml as follows and stored my personal access token in the pipeline variable. trigger:
Read more >
Using secrets from Azure Key Vault in a pipeline
It will give you a JSON output as shown in the image. ... az account show ... If not already logged in, login...
Read more >
Azure DevOps integration - SonarQube Documentation
If you're using Developer Edition or above, this is also the first step in adding pull request decoration. To set up the import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found