Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/azure-cli/azure/cli/command_modules/appservice/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,54 @@
text: az webapp create-remote-connection --name MyWebApp --resource-group MyResourceGroup
"""

helps['webapp exec'] = """
type: command
short-summary: Open an interactive shell session or run a command in a Linux web app container.
long-summary: |
Interact with your Linux web app container in two modes:
- 'shell' (default): open an interactive shell session with your main app container.
- 'execute': run a fire-and-forget command in your main app container; it returns immediately without output.

Only supported for Linux App Service plans.
Shell sessions are intended for diagnostics, not long-running work: a session ends automatically after
3 hours of inactivity, and may also end if the underlying instance is reimaged or platform components are updated.
For 'execute' mode, redirect output to a file inside the command to capture results (see examples).
examples:
- name: Run a direct command in the container
text: >
az webapp exec -g MyResourceGroup -n MyWebapp --mode execute --command mkdir --args "/home/site/newdir"
- name: Run a bash command and redirect output to a file
text: >
az webapp exec -g MyResourceGroup -n MyWebapp --mode execute --command bash --args "-c" "pwd &> pwd.txt"
- name: Create a file in a specific working directory
text: >
az webapp exec -g MyResourceGroup -n MyWebapp --mode execute --command touch --args "newfile.txt" --cwd /home/site
- name: Run a Python script in the container
text: >
az webapp exec -g MyResourceGroup -n MyWebapp --mode execute --command python --args "/home/site/wwwroot/script.py"
- name: Run a Node.js script in the container
text: >
az webapp exec -g MyResourceGroup -n MyWebapp --mode execute --command node --args "/home/site/wwwroot/app.js"
- name: Execute a command on a specific instance
text: >
az webapp exec -g MyResourceGroup -n MyWebapp --mode execute --command touch --args "newfile.txt" --instance MyInstanceId
- name: Execute a command on all instances
text: >
az webapp exec -g MyResourceGroup -n MyWebapp --mode execute --command touch --args "newfile.txt" --instance all
- name: Execute a command on a deployment slot
text: >
az webapp exec -g MyResourceGroup -n MyWebapp -s staging --mode execute --command touch --args "newfile.txt"
- name: Start an interactive shell session with the web app container
text: >
az webapp exec -g MyResourceGroup -n MyWebapp --mode shell
- name: Start an interactive shell session on a specific instance
text: >
az webapp exec -g MyResourceGroup -n MyWebapp --mode shell --instance MyInstanceId
- name: Start an interactive shell session using a specific shell
text: >
az webapp exec -g MyResourceGroup -n MyWebapp --mode shell --shell /bin/sh
"""

helps['webapp delete'] = """
type: command
short-summary: Delete a web app.
Expand Down
25 changes: 25 additions & 0 deletions src/azure-cli/azure/cli/command_modules/appservice/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,3 +1605,28 @@ def load_arguments(self, _):
c.argument('environment_name', help="Name of the environment of static site")
with self.argument_context('staticwebapp enterprise-edge') as c:
c.argument("no_register", help="Don't try to register the Microsoft.CDN provider. Registration can be done manually with: az provider register --wait --namespace Microsoft.CDN. For more details, please review the documentation available at https://go.microsoft.com/fwlink/?linkid=2184995 .", default=False)
with self.argument_context('webapp exec') as c:
c.argument('name', arg_type=webapp_name_arg_type, id_part=None)
c.argument('command', options_list=['--command'],
help="The command or executable to run in the container (e.g., touch, mkdir, bash, python)."
" Used only in 'execute' mode.")
c.argument('args', options_list=['--args'], nargs='+',
help='Arguments to pass to the command. For shell commands, use: --command bash --args "-c" "your command here".'
" Used only in 'execute' mode.")
c.argument('mode',
help="Execution mode. 'shell' (default): Starts an interactive shell session with the main"
" web app container. 'execute': Starts command execution and returns immediately without"
" returning command output.",
arg_type=get_enum_type(['shell', 'execute']), default='shell')
c.argument('working_directory', options_list=['--working-directory', '--cwd'],
help="Working directory for command execution. Defaults to the container's working directory."
" Used only in 'execute' mode.")
c.argument('instance', options_list=['--instance', '-i'],
help='Webapp instance(s) to target. Specify a comma-separated list of instance IDs'
' (use "az webapp list-instances" to get IDs) or "all" for all instances. Defaults to a random instance.'
' "all" is supported only in \'execute\' mode.')
c.argument('shell', options_list=['--shell'],
help="Absolute path of the shell to launch (e.g. /bin/sh). "
"Defaults to /bin/bash. Used only in 'shell' mode.")
c.argument('slot', options_list=['--slot', '-s'],
help='Name of the web app slot. Default to the production slot if not specified.')
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,14 @@ def load_command_table(self, _):

logicapp_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.appservice.logicapp.custom#{}')

webapp_exec_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.appservice.webapp_exec#{}')

with self.command_group('webapp', webapp_sdk) as g:
g.custom_command('create', 'create_webapp', exception_handler=ex_handler_factory(), validator=validate_vnet_integration)
g.custom_command('up', 'webapp_up', exception_handler=ex_handler_factory(), validator=validate_webapp_up,
deprecate_info=g.deprecate(redirect='webapp create and webapp deploy'))
g.custom_command('ssh', 'ssh_webapp', exception_handler=ex_handler_factory(), is_preview=True)
g.custom_command('exec', 'webapp_exec', custom_command_type=webapp_exec_custom, exception_handler=ex_handler_factory(), is_preview=True)
g.custom_command('list', 'list_webapp', table_transformer=transform_web_list_output)
g.custom_show_command('show', 'show_app', table_transformer=transform_web_output)
g.custom_command('delete', 'delete_webapp')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from azure.cli.core.azclierror import (InvalidArgumentValueError, MutuallyExclusiveArgumentError, ResourceNotFoundError,
RequiredArgumentMissingError, ValidationError, CLIInternalError,
UnclassifiedUserFault, AzureResponseError, AzureInternalError,
ArgumentUsageError, FileOperationError)
ArgumentUsageError, FileOperationError, AzureConnectionError)

from .tunnel import TunnelServer

Expand Down
Loading
Loading