Skip to content

Authorization error when trying to add reviewers with az pr create command #27549

@scottlarnach

Description

@scottlarnach

Describe the bug

I am using the "az pr create" command in a pipeline and this pipeline executes successfully, unless I try to add reviewers. As soon as I add "--reviewers email@company.com" to the command, the pipeline fails with the error "ERROR: The requested resource requires user authentication: https://vssps.dev.azure.com/Company/_apis/Identities?searchFilter=General&filterValue=email%40company.com"

I have the environment variable AZURE_DEVOPS_EXT_PAT set to the correct PAT token.

I have tested running the command minus --reviewers then manually adding reviewers, with the account executing the pipeline, and this works fine.

This also fails using the "az repos pr reviewer add" command.

I tried the same thing using Invoke-RestMethod and the Azure REST-API and this worked successfully, using the same PAT token.

Related command

az repos pr create --org https://dev.azure.com/Company/ -r repo -p project -s $sourceBranch -t $targetBranch --work-items $pbi.id --squash --auto-complete --delete-source-branch --transition-work-items --reviewers email@company.com

Errors

ERROR: The requested resource requires user authentication: https://vssps.dev.azure.com/Company/_apis/Identities?searchFilter=General&filterValue=email%40company.com

Issue script & Debug output

[09:34:14]i: [Step 6/6] PowerShell running in non-virtual agent context
[09:34:14] : [Step 6/6] PowerShell Executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
[09:34:14] : [Step 6/6] Working directory: C:\Work\D20x_UserManual\Documentation
[09:34:14] : [Step 6/6] Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
[09:34:14] : [Step 6/6] PowerShell arguments: -NoProfile, -NonInteractive, -ExecutionPolicy, ByPass, -File, C:\Work\D20x_UserManual\Documentation\CreatePR.ps1, -Version, 20.4, -targetBranch, branch
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Command arguments: ['repos', 'pr', 'create', '--org', 'https://dev.azure.com/org/', '-r', 'repo', '-p', 'project', '-s', 'branch', '-t', 'branch', '--work-items', '248762', '--squash', '--auto-complete', '--delete-source-branch', '--transition-work-items', '--reviewers', 'redacteduser@company.com', '--debug']
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: init debug log:
[09:34:19]W: [Step 6/6] Cannot enable color.
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Event: Cli.PreExecute []
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x0286A9B8>, <function OutputProducer.on_global_arguments at 0x02968BF8>, <function CLIQuery.on_global_arguments at 0x02988850>]
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Modules found from index for 'repos': ['azext_devops']
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Loading command modules:
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Name Load Time Groups Commands
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Total (0) 0.000 0 0
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Loading extensions:
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Name Load Time Groups Commands Directory
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: azure-devops 0.173 60 192 C:\Users\user.azure\cliextensions\azure-devops
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Total (1) 0.173 60 192
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Loaded 60 groups, 192 commands.
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Found a match in the command table.
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Raw command : repos pr create
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Command table: repos pr create
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x03CDBA90>]
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\user.azure\commands\2023-10-09.09-34-19.repos_pr_create.3340.log'.
[09:34:19]W: [Step 6/6] INFO: az_command_data_logger: command args: repos pr create --org {} -r {} -p {} -s {} -t {} --work-items {} --squash --auto-complete --delete-source-branch --transition-work-items --reviewers {} --debug
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x03D04BF8>]
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x03D12B68>, <function register_cache_arguments..add_cache_arguments at 0x03D12D60>]
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
[09:34:19]W: [Step 6/6] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x02968C40>, <function CLIQuery.handle_query_parameter at 0x02988898>, <function register_ids_argument..parse_ids_arguments at 0x03D12D18>, <function DevCommandsLoader.post_parse_args at 0x03D3FC40>]
[09:34:19]W: [Step 6/6] INFO: az_command_data_logger: extension name: azure-devops
[09:34:19]W: [Step 6/6] INFO: az_command_data_logger: extension version: 0.26.0
[09:34:19]W: [Step 6/6] DEBUG: cli.azext_devops.dev.common.services: PAT is present which can be used against this instance
[09:34:19]W: [Step 6/6] DEBUG: cli.azure.cli.core: Current cloud config:
[09:34:19]W: [Step 6/6] AzureCloud
[09:34:19]W: [Step 6/6] DEBUG: cli.azext_devops.dev.common.services: az login is not present
[09:34:19]W: [Step 6/6] DEBUG: cli.azext_devops.dev.common.services: There are no active accounts.
[09:34:19]W: [Step 6/6] Traceback (most recent call last):
[09:34:19]W: [Step 6/6] File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_profile.py", line 537, in get_current_account_user
[09:34:19]W: [Step 6/6] File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_profile.py", line 546, in get_subscription
[09:34:19]W: [Step 6/6] knack.util.CLIError: Please run 'az login' to setup account.
[09:34:19]W: [Step 6/6]
[09:34:19]W: [Step 6/6] During handling of the above exception, another exception occurred:
[09:34:19]W: [Step 6/6]
[09:34:19]W: [Step 6/6] Traceback (most recent call last):
[09:34:19]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\dev\common\services.py", line 61, in _get_credentials
[09:34:19]W: [Step 6/6] token_from_az_login = get_token_from_az_logins(organization, pat_token_present)
[09:34:19]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\dev\common\services.py", line 118, in get_token_from_az_logins
[09:34:19]W: [Step 6/6] dummy_user = profile.get_current_account_user() # noqa: F841
[09:34:19]W: [Step 6/6] File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_profile.py", line 539, in get_current_account_user
[09:34:19]W: [Step 6/6] knack.util.CLIError: There are no active accounts.
[09:34:19]W: [Step 6/6] INFO: cli.azext_devops.dev.common.services: received PAT from environment variable
[09:34:19]W: [Step 6/6] INFO: cli.azext_devops.dev.common.services: Creating connection with personal access token.
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
[09:34:19]W: [Step 6/6] DEBUG: cli.azext_devops.dev.common.telemetry: Azure devops telemetry enabled.
[09:34:19]W: [Step 6/6] DEBUG: cli.azext_devops.dev.common.telemetry: Logging telemetry to azure devops server.
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk._file_cache: Loading cache file: C:\Users\user.azure-devops\python-sdk\cache\options.json
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk._file_cache: Loading cache file: C:\Users\user.azure-devops\python-sdk\cache\resources.json
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk._file_cache: attempting to read file C:\Users\user.azure-devops\python-sdk\cache\options.json as utf-8-sig
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk._file_cache: attempting to read file C:\Users\user.azure-devops\python-sdk\cache\resources.json as utf-8-sig
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.connection: File cache hit for resources on: https://dev.azure.com/org
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.client: File cache hit for options on: https://dev.azure.com/org
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.client: Route template: _apis/{area}/{resource}
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.client: Api version '5.0-preview.1'
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.client: POST https://dev.azure.com/org/_apis/CustomerIntelligence/Events
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.client: Request content: [{'area': 'AzureDevopsCli', 'feature': 'repos', 'properties': {'Command': 'pr create', 'Args': 'project repository source_branch target_branch organization', 'ShellType': 'cmd', 'IsInteractive': 'False', 'OutputType': 'json', 'OrgPresentInCommand': True, 'ProjectPresentInCommand': True, 'RepoPresentInCommand': True}}]
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http: Configuring redirects: allow=True, max=30
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http: Configuring request: timeout=100, verify=True, cert=None
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http: Configuring proxies: ''
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http: Evaluate proxies against ENV settings: True
[09:34:19]W: [Step 6/6] DEBUG: urllib3.connectionpool: Starting new HTTPS connection (1): dev.azure.com:443
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.client: File cache hit for options on: https://vssps.dev.azure.com/org
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.client: Route template: _apis/{resource}/{identityId}
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.client: Api version '5.0'
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.client: GET https://vssps.dev.azure.com/org/_apis/Identities?searchFilter=General&filterValue=user%40company.com
[09:34:19]W: [Step 6/6] DEBUG: azext_devops.devops_sdk.client: Request content: None
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http: Configuring redirects: allow=True, max=30
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http: Configuring request: timeout=100, verify=True, cert=None
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http: Configuring proxies: ''
[09:34:19]W: [Step 6/6] DEBUG: msrest.universal_http: Evaluate proxies against ENV settings: True
[09:34:19]W: [Step 6/6] DEBUG: urllib3.connectionpool: Starting new HTTPS connection (1): vssps.dev.azure.com:443
[09:34:19]W: [Step 6/6] DEBUG: urllib3.connectionpool: https://dev.azure.com:443 "POST /org/_apis/CustomerIntelligence/Events HTTP/1.1" 204 0
[09:34:19]W: [Step 6/6] DEBUG: urllib3.connectionpool: https://vssps.dev.azure.com:443 "GET /org/_apis/Identities?searchFilter=General&filterValue=user%40company.com HTTP/1.1" 401 0
[09:34:19]W: [Step 6/6] DEBUG: msrest.exceptions: The requested resource requires user authentication: https://vssps.dev.azure.com/org/_apis/Identities?searchFilter=General&filterValue=user%40company.com
[09:34:19]W: [Step 6/6] DEBUG: cli.azext_devops.dev.common.exception_handler: handling vsts auth error
[09:34:20]W: [Step 6/6] DEBUG: cli.azure.cli.core.azclierror: Traceback (most recent call last):
[09:34:20]W: [Step 6/6] File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 697, in _run_job
[09:34:20]W: [Step 6/6] File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 333, in call
[09:34:20]W: [Step 6/6] File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
[09:34:20]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\dev\repos\pull_request.py", line 175, in create_pull_request
[09:34:20]W: [Step 6/6] pr.reviewers = _resolve_reviewers_as_refs(reviewers, organization)
[09:34:20]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\dev\repos\pull_request.py", line 605, in _resolve_reviewers_as_refs
[09:34:20]W: [Step 6/6] resolved_reviewers.append(IdentityRefWithVote(id=resolve_identity_as_id(reviewer, organization)))
[09:34:20]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\dev\common\identities.py", line 20, in resolve_identity_as_id
[09:34:20]W: [Step 6/6] identity = resolve_identity(identity_filter, organization)
[09:34:20]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\dev\common\identities.py", line 61, in resolve_identity
[09:34:20]W: [Step 6/6] identities = identity_client.read_identities(search_filter='General',
[09:34:20]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\devops_sdk\v5_0\identity\identity_client.py", line 121, in read_identities
[09:34:20]W: [Step 6/6] response = self._send(http_method='GET',
[09:34:20]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\devops_sdk\client.py", line 90, in _send
[09:34:20]W: [Step 6/6] response = self._send_request(request=request, headers=headers, content=content, media_type=media_type)
[09:34:20]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\devops_sdk\client.py", line 54, in _send_request
[09:34:20]W: [Step 6/6] self._handle_error(request, response)
[09:34:20]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\devops_sdk\client.py", line 253, in _handle_error
[09:34:20]W: [Step 6/6] raise AzureDevOpsAuthenticationError(full_message_format.format(error_message=error_message,
[09:34:20]W: [Step 6/6] azext_devops.devops_sdk.exceptions.AzureDevOpsAuthenticationError: The requested resource requires user authentication: https://vssps.dev.azure.com/org/_apis/Identities?searchFilter=General&filterValue=user%40company.com
[09:34:20]W: [Step 6/6]
[09:34:20]W: [Step 6/6] During handling of the above exception, another exception occurred:
[09:34:20]W: [Step 6/6]
[09:34:20]W: [Step 6/6] Traceback (most recent call last):
[09:34:20]W: [Step 6/6] File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
[09:34:20]W: [Step 6/6] File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 663, in execute
[09:34:20]W: [Step 6/6] File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 726, in _run_jobs_serially
[09:34:20]W: [Step 6/6] File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 718, in run_job
[09:34:20]W: [Step 6/6] File "C:\Users\user.azure\cliextensions\azure-devops\azext_devops\dev\common\exception_handler.py", line 22, in azure_devops_exception_handler
[09:34:20]W: [Step 6/6] raise CLIError(ex)
[09:34:20]W: [Step 6/6] knack.util.CLIError: The requested resource requires user authentication: https://vssps.dev.azure.com/org/_apis/Identities?searchFilter=General&filterValue=user%40company.com
[09:34:20]W: [Step 6/6]
[09:34:20]W: [Step 6/6] ERROR: cli.azure.cli.core.azclierror: The requested resource requires user authentication: https://vssps.dev.azure.com/org/_apis/Identities?searchFilter=General&filterValue=user%40company.com
[09:34:20]W: [Step 6/6] ERROR: az_command_data_logger: The requested resource requires user authentication: https://vssps.dev.azure.com/org/_apis/Identities?searchFilter=General&filterValue=user%40company.com
[09:34:20]W: [Step 6/6] DEBUG: cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x03CDBBB0>]
[09:34:20]W: [Step 6/6] INFO: az_command_data_logger: exit code: 1
[09:34:20]W: [Step 6/6] INFO: cli.main: Command ran in 1.646 seconds (init: 0.625, invoke: 1.022)
[09:34:20]W: [Step 6/6] INFO: telemetry.main: Begin splitting cli events and extra events, total events: 1
[09:34:20]W: [Step 6/6] INFO: telemetry.client: Accumulated 0 events. Flush the clients.
[09:34:20]W: [Step 6/6] INFO: telemetry.main: Finish splitting cli events and extra events, cli events: 1
[09:34:20]W: [Step 6/6] INFO: telemetry.save: Save telemetry record of length 3574 in cache
[09:34:20]W: [Step 6/6] INFO: telemetry.main: Begin creating telemetry upload process.
[09:34:20]W: [Step 6/6] INFO: telemetry.process: Creating upload process: "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\cli\telemetry_init
.pyc C:\Users\user.azure"
[09:34:20]W: [Step 6/6] INFO: telemetry.process: Return from creating process
[09:34:20]W: [Step 6/6] INFO: telemetry.main: Finish creating telemetry upload process.
[09:34:20] : [Step 6/6] Process exited with code 0

Expected behavior

PR should be created and reviewers added.

Environment Summary

azure-cli 2.53.0

core 2.53.0
telemetry 1.1.0

Extensions:
azure-devops 0.26.0

Dependencies:
msal 1.24.0b2
azure-mgmt-resource 23.1.0b2

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\username.azure\cliextensions'

Python (Windows) 3.10.10 (tags/v3.10.10:aad5f6a, Feb 7 2023, 17:05:00) [MSC v.1929 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Auto-AssignAuto assign by botDevOpsService AttentionThis issue is responsible by Azure service team.act-platform-engineering-squadcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions