Azure / azure-cli

Azure Command-Line Interface
MIT License
4k stars 2.98k forks source link

Check for TTY existence before prompting #29087

Open codepic opened 4 months ago

codepic commented 4 months ago

Describe the bug

I am running an Azure DevOps pipeline, more specifically az deployment group create.

The pipeline fails with a simple ERROR: and no details whatsoever.

I need to pass --debug into Azure CLI in order to get into the details of the error.

DEBUG: cli.knack.prompting: No tty available.
DEBUG: cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 701, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 334, in __call__
  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
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/resource/custom.py", line 607, in deploy_arm_template_at_resource_group
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/prompting.py", line 71, in prompt_y_n
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/prompting.py", line 79, in _prompt_bool
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/prompting.py", line 28, in verify_is_a_tty
knack.prompting.NoTTYException

As you can see, the Azure CLI finds out there is something missing and will call knack.prompting in order to get user input.

Only then, knack.prompting will call verify_is_a_tty and throws knack.prompting.NoTTYException.

Related command

az deployment group create

Errors

DEBUG: cli.knack.prompting: No tty available.
DEBUG: cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 701, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 334, in __call__
  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
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/resource/custom.py", line 607, in deploy_arm_template_at_resource_group
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/prompting.py", line 71, in prompt_y_n
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/prompting.py", line 79, in _prompt_bool
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/prompting.py", line 28, in verify_is_a_tty
knack.prompting.NoTTYException

Issue script & Debug output

exec {
    & az deployment group create (Get-BicepDeploymentArgs) `
        --name $deploymentName `
        --resource-group $rg_name `
        --template-file $bicepFile `
        --parameters `
        module=$Module `
        environment=$Environment `
        enable_ingress=$enable_ingress `
        enable_dapr=$enable_dapr `
        location=$Location `
        tags=$tags `
        container=$container `
        env=$vars `
        --verbose `
        --debug `
}
cd D:\a\1\s
$deploymentName: dep-mapapi-2024-06-04-09-04-27
$rg_name: al-tp-rg
$bicepFile: ./modules/_lib/ca/main.bicep
$Module: mapapi
$Environment: dev
$enable_ingress: true
$enable_dapr: true
$Location: swedencentral
$tags: {'Partner':'Amban Nordic Oy','CreatedBy':'fv-az372-492\\vssadministrator','Module':'MAPAPI','Created':'2024-06-04','Environment':'DEV'}
$container: [{'Name':'al-tp-mapapi','Image':'acrcaealtpdevswc.azurecr.io/al-tp-mapapi:refs-pull-110-merge','MinReplicas':2,'MaxReplicas':25,'Cpu':'1.75','Memory':'3.50','Scale':{'Http':{'ConcurrentRequests':200}}}]
$vars: [{'name':'Variable','value':'Value'}]
DEBUG: cli.knack.prompting: No tty available.
DEBUG: cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 701, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 334, in __call__
  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
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/resource/custom.py", line 607, in deploy_arm_template_at_resource_group
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/prompting.py", line 71, in prompt_y_n
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/prompting.py", line 79, in _prompt_bool
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/prompting.py", line 28, in verify_is_a_tty
knack.prompting.NoTTYException

Expected behavior

Azure CLI checks if TTY exists when an argument is missing and simply throws an exception with the missing argument name when TTY cannot be found.

Environment Summary

azure-cli                         2.60.0 *

core                              2.60.0 *
telemetry                          1.1.0

Extensions:
azure-devops                       1.0.0

Dependencies:
msal                              1.28.0
azure-mgmt-resource             23.1.0b2

Additional context

Azure DevOps, ubuntu-latest and windows-latest.

azure-client-tools-bot-prd[bot] commented 4 months ago

Hi @codepic,

2.60.0 is not the latest Azure CLI(2.61.0).

If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

yonzhan commented 4 months ago

Thank you for opening this issue, we will look into it.

azure-client-tools-bot-prd[bot] commented 4 months ago
Hi @codepic Find similar issue https://github.com/Azure/azure-cli/issues/11099.
Issue title az aks upgrade tty error in Azure DevOps agent
Create time 2019-11-04
Comment number 11

Possible solution: As mentioned in the previous issue, the error message indicates that the program needs user input, which is not possible in DevOps as it doesn't have a tty. One solution is to add a parameter to skip or override human input. Another solution is to adjust the command so that it doesn't reach the line where user input is needed. However, it seems like this issue has been resolved by passing --yes flag.


Please confirm if this resolves your issue.

microsoft-github-policy-service[bot] commented 4 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/deployments-owners.

codepic commented 4 months ago

Hi @codepic Find similar issue #11099.

Issue title az aks upgrade tty error in Azure DevOps agent Create time 2019-11-04 Comment number 11 Possible solution: As mentioned in the previous issue, the error message indicates that the program needs user input, which is not possible in DevOps as it doesn't have a tty. One solution is to add a parameter to skip or override human input. Another solution is to adjust the command so that it doesn't reach the line where user input is needed. However, it seems like this issue has been resolved by passing --yes flag.

Please confirm if this resolves your issue.

Passing --yes when you don't know what the underlying issue is, is not a solution.

Clearly communicating what Azure CLI attempted and what stopped it from continuing, is the answer.

F.ex. in this particular case, a message like Azure CLI attempted to request user input with message 'Are you sure you want to execute the deployment? (y/n):' but no TTY exists. would be much more preferable than ERROR: which leads to 4 hours of wasted debugging effort (multiplied by how many times this ambiguous error is shown to Azure CLI users, which must be thousands every year).

It all falls down to TCO of Azure and our customers will pay it in their consulting bill.