Skip to content

Commit 5f26a84

Browse files
authored
{App Service} az webapp deploy: Add friendly name used to identify the deployment (#33940)
1 parent ae51706 commit 5f26a84

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎src/azure-cli/azure/cli/command_modules/appservice/_params.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ def load_arguments(self, _):
11101110
c.argument('enriched_errors', options_list=['--enriched-errors'],
11111111
help='If true, deployment failures will show context-enriched diagnostics with error codes, suggested fixes, and Copilot prompts. Enabled by default; use --enriched-errors false to disable.',
11121112
arg_type=get_three_state_flag(), default=True)
1113+
c.argument('tag', help='Linux only. A friendly name used to identify the deployment.')
11131114

11141115
with self.argument_context('functionapp deploy') as c:
11151116
c.argument('name', options_list=['--name', '-n'], help='Name of the function app to deploy to.')

‎src/azure-cli/azure/cli/command_modules/appservice/custom.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11432,7 +11432,8 @@ def perform_onedeploy_webapp(cmd,
1143211432
slot=None,
1143311433
track_status=True,
1143411434
enable_kudu_warmup=True,
11435-
enriched_errors=True):
11435+
enriched_errors=True,
11436+
tag=None):
1143611437
params = OneDeployParams()
1143711438

1143811439
params.cmd = cmd
@@ -11451,6 +11452,7 @@ def perform_onedeploy_webapp(cmd,
1145111452
params.track_status = track_status
1145211453
params.enable_kudu_warmup = enable_kudu_warmup
1145311454
params.enriched_errors = enriched_errors
11455+
params.tag = tag
1145411456

1145511457
# When a slot is targeted, fetch the slot's Site (not production) so the
1145611458
# cached model matches what every downstream consumer expects — slots have
@@ -11459,6 +11461,9 @@ def perform_onedeploy_webapp(cmd,
1145911461
app = _generic_site_operation(cmd.cli_ctx, resource_group_name, name, 'get', slot)
1146011462
params._cached_site = app # pylint: disable=protected-access
1146111463
params.is_linux_webapp = is_linux_webapp(app)
11464+
if tag is not None and not params.is_linux_webapp:
11465+
logger.warning("--tag is only supported for Linux web apps and will be ignored.")
11466+
params.tag = None
1146211467

1146311468
# Warn that zip deploy won't auto-build on Linux
1146411469
if params.is_linux_webapp and artifact_type in (None, 'zip'):
@@ -11494,6 +11499,7 @@ def __init__(self):
1149411499
self.is_linux_webapp = None
1149511500
self.is_functionapp = None
1149611501
self.enriched_errors = True
11502+
self.tag = None
1149711503
# Per-invocation caches. Populated during a single deploy and
1149811504
# cleared in _perform_onedeploy_internal's `finally` block. These MUST
1149911505
# NOT be logged, serialized, or accessed outside the current call
@@ -11634,6 +11640,9 @@ def _build_onedeploy_scm_url(params):
1163411640
if params.target_path is not None:
1163511641
deploy_url = deploy_url + '&path=' + quote(params.target_path)
1163611642

11643+
if params.tag is not None:
11644+
deploy_url = deploy_url + '&tag=' + quote(params.tag, safe='')
11645+
1163711646
return deploy_url
1163811647

1163911648

@@ -11751,6 +11760,7 @@ def _get_onedeploy_request_body(params):
1175111760
"ignorestack": params.should_ignore_stack,
1175211761
"clean": params.is_clean_deployment,
1175311762
"restart": params.should_restart,
11763+
"tag": params.tag,
1175411764
}
1175511765
}
1175611766
body = {"properties": {k: v for k, v in body["properties"].items() if v is not None}}

‎src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,46 @@ def __init__(self, status_code):
15051505
self.status_code = status_code
15061506

15071507

1508+
class TestOneDeployTag(unittest.TestCase):
1509+
1510+
def test_scm_url_includes_encoded_tag(self):
1511+
from azure.cli.command_modules.appservice.custom import OneDeployParams, _build_onedeploy_scm_url
1512+
params = OneDeployParams()
1513+
params.artifact_type = 'zip'
1514+
params.tag = 'release 2026/08'
1515+
1516+
with mock.patch('azure.cli.command_modules.appservice.custom._get_or_fetch_scm_url',
1517+
return_value='https://example.scm.azurewebsites.net'):
1518+
result = _build_onedeploy_scm_url(params)
1519+
1520+
self.assertEqual(result, 'https://example.scm.azurewebsites.net/api/publish?type=zip&tag=release%202026%2F08')
1521+
1522+
@mock.patch('azure.cli.command_modules.appservice.custom._perform_onedeploy_internal')
1523+
@mock.patch('azure.cli.command_modules.appservice.custom._generic_site_operation')
1524+
def test_webapp_deploy_ignores_tag_for_windows_webapp(self, site_operation_mock, perform_deploy_mock):
1525+
from azure.cli.command_modules.appservice.custom import perform_onedeploy_webapp
1526+
site_operation_mock.return_value = mock.MagicMock(kind='app', reserved=False)
1527+
1528+
with mock.patch('azure.cli.command_modules.appservice.custom.logger.warning') as warning_mock:
1529+
perform_onedeploy_webapp(mock.MagicMock(), 'myRG', 'myApp', tag='windows-tag')
1530+
1531+
warning_mock.assert_any_call('--tag is only supported for Linux web apps and will be ignored.')
1532+
self.assertIsNone(perform_deploy_mock.call_args.args[0].tag)
1533+
1534+
def test_arm_body_includes_tag(self):
1535+
import json
1536+
from azure.cli.command_modules.appservice.custom import OneDeployParams, _get_onedeploy_request_body
1537+
params = OneDeployParams()
1538+
params.src_url = 'https://example.com/app.zip'
1539+
params.artifact_type = 'zip'
1540+
params.tag = 'release-2026-08'
1541+
1542+
body, file_hash = _get_onedeploy_request_body(params)
1543+
1544+
self.assertEqual(json.loads(body)['properties']['tag'], 'release-2026-08')
1545+
self.assertIsNone(file_hash)
1546+
1547+
15081548
class TestCreateAppServicePlanDefaults(unittest.TestCase):
15091549
"""Tests for create_app_service_plan default SKU behavior"""
15101550

0 commit comments

Comments
 (0)