azure-cli: az container exec in azure devops throws (25, 'Inappropriate ioctl for device')

Az version 2.3.1

Describe the bug

When trying to use Azure DevOps Pipelines Azure CLI task az container exec the shell outputs errors.

To Reproduce

az container exec --resource-group myRG --name myImageName --exec-command ./run.sh

Expected behavior

To be able to display the output of the container.

Environment summary

Azure Devops free agent running Ubuntu 18.04

Additional context

This error message is thrown:

 [command]/bin/bash /home/vsts/work/_temp/azureclitaskscript1588671209398.sh
 The command failed with an unexpected error. Here is the traceback:
 
 (25, 'Inappropriate ioctl for device')
 Traceback (most recent call last):
   File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 215, in invoke
     cmd_result = self.invocation.execute(args)
   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 625, in execute
     raise ex
   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 689, in _run_jobs_serially
     results.append(self._run_job(expanded_arg, cmd_copy))
   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 682, in _run_job
     six.reraise(*sys.exc_info())
   File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise
     raise value
   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 659, in _run_job
     result = cmd_copy(params)
   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 324, in __call__
     return self.handler(*args, **kwargs)
   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 531, in default_command_handler
     return op(**command_args)
   File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/container/custom.py", line 621, in container_exec
     _start_exec_pipe(execContainerResponse.web_socket_uri, execContainerResponse.password)
   File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/container/custom.py", line 655, in _start_exec_pipe
     oldtty = termios.tcgetattr(sys.stdin)
 termios.error: (25, 'Inappropriate ioctl for device')
 
 To open an issue, please run: 'az feedback'

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 13
  • Comments: 31 (2 by maintainers)

Most upvoted comments

@navba-MSFT this is still an issue, please reopen this issue.

In the end I emulated tty using the following

script --return --quiet -c "az container exec --resource-group myRG --name myImageName --exec-command ./run.sh'" /dev/null

still seems to be an issue in 2024 @navba-MSFT

Getting this issue running against container app on an azure devops Ubuntu 22.04 agent

 az containerapp exec -n my-container -g my-rg   --command "./manage.py my_command"
Please ensure there is an alive replica. 
Exception in thread Thread-1 (read_ssh):
Traceback (most recent call last):
  File "/opt/az/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/opt/az/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/az/lib/python3.11/site-packages/azure/cli/command_modules/containerapp/_ssh_utils.py", line 123, in read_ssh
    _resize_terminal(connection)
  File "/opt/az/lib/python3.11/site-packages/azure/cli/command_modules/containerapp/_ssh_utils.py", line 154, in _resize_terminal
    size = os.get_terminal_size()
           ^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 25] Inappropriate ioctl for device
ERROR: The command failed with an unexpected error. Here is the traceback:
ERROR: (25, 'Inappropriate ioctl for device')
Traceback (most recent call last):
  File "/opt/az/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
    mode = tcgetattr(fd)
           ^^^^^^^^^^^^^
termios.error: (25, 'Inappropriate ioctl for device')
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

@navba-MSFT - Any update on this? Seeing the same behaviour on the following setup, running on ubuntu-latest:

azure-cli                         2.37.0
core                              2.37.0
telemetry                          1.0.6

Extensions:
azure-devops                      0.25.0

Dependencies:
msal                            1.18.0b1
azure-mgmt-resource             21.1.0b1

The workaround from @gary-x0pa works, but presents me with a different problem.