az containerapp exec is throwing exception in azure cli task of azure devops pipeline

95 Views Asked by At

`I'm trying to execute a command in azure containerapp its giving the following error:

2024-01-31T20:47:13.9713698Z Exception in thread Thread-1 (read_ssh): 2024-01-31T20:47:13.9718303Z Traceback (most recent call last): 2024-01-31T20:47:13.9723276Z File "threading.py", line 1038, in _bootstrap_inner 2024-01-31T20:47:13.9723860Z File "threading.py", line 975, in run

inlineScript: 'az containerapp exec --name test --resource-group test-RG --command"/bin/shpostbuild.sh"'

Note: The same exec command is working as expected if I'm trying to execute in local powershell

Issue is with exec command to container. I want to execute the command in azure container from devops pipeline `

1

There are 1 best solutions below

0
Bright Ran-MSFT On BEST ANSWER

This is a known issue/limitation for "az containerapp exec" and "az container exec" commands as they are interactive mode. So, the commands cannot work when running in Azure Pipelines with non-interactive mode.

See below articles:


As a workaround has been mentioned in above articles, you can try to run the following command line using the Azure CLI task on an Ubuntu agent (e.g., ubuntu-latest). I have tested this command line in pipeline, and it can work fine.

script -q -c 'az containerapp exec --name test --resource-group test-RG --command"/bin/shpostbuild.sh"'

Use AzureCLI@2 task with bash (Shell) on Ubuntu agent.

- task: AzureCLI@2
  displayName: 'Azure CLI'
  inputs:
    azureSubscription: {ARM Service Connection}
    scriptType: bash
    scriptLocation: inlineScript
    inlineScript: 'script -q -c ''az containerapp exec --name test --resource-group test-RG --command"/bin/shpostbuild.sh"'''

Or use AzureCLI@2 task with pscore (PowerShell Core) on Ubuntu agent.

- task: AzureCLI@2
  displayName: 'Azure CLI'
  inputs:
    azureSubscription: {ARM Service Connection}
    scriptType: pscore
    scriptLocation: inlineScript
    inlineScript: 'script -q -c ''az containerapp exec --name test --resource-group test-RG --command"/bin/shpostbuild.sh"'''