Skip to content
Open
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
27 changes: 25 additions & 2 deletions src/azure-cli/azure/cli/command_modules/containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,12 @@ def start_containerappsjob(cmd,

template_def = None

if image is not None:
# Check if any container override parameters are provided
has_container_overrides = (image is not None or container_name is not None or
env_vars is not None or startup_command is not None or
args is not None or cpu is not None or memory is not None)

if has_container_overrides:
template_def = JobExecutionTemplateModel
container_def = ContainerModel
resources_def = None
Expand All @@ -1565,7 +1570,25 @@ def start_containerappsjob(cmd,
resources_def["memory"] = memory

container_def["name"] = container_name if container_name else name
container_def["image"] = image if not is_registry_msi_system(registry_identity) else HELLO_WORLD_IMAGE

# If no image is provided, fetch the existing job's image
if image is not None:
container_def["image"] = image if not is_registry_msi_system(registry_identity) else HELLO_WORLD_IMAGE
else:
# Fetch the existing job definition to get the default image
try:
containerappjob_def = ContainerAppsJobClient.show(cmd=cmd, resource_group_name=resource_group_name, name=name)
except Exception as e:
handle_raw_exception(e)

if not containerappjob_def:
raise ResourceNotFoundError("The containerapp job '{}' does not exist".format(name))

existing_image = safe_get(containerappjob_def, "properties", "template", "containers", default=[{}])[0].get("image")
if not existing_image:
raise ValidationError("Could not find an existing image for the containerapp job '{}'. Please specify --image.".format(name))
container_def["image"] = existing_image if not is_registry_msi_system(registry_identity) else HELLO_WORLD_IMAGE
Comment on lines 1574 to 1590
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for fetching the existing job's image (lines 1578-1590) will be executed every time has_container_overrides is true but image is None. This means even if the user only wants to override cpu or memory without changing the image, the code will unnecessarily fetch the job definition. Consider moving this fetch outside the conditional block or only fetching when needed for command/args overrides without an image.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@Greedygre Greedygre Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed the original code looks weird:

        container_def["image"] = image if not is_registry_msi_system(registry_identity) else HELLO_WORLD_IMAGE

It set image to HELLO_WORLD_IMAGE when registry_identity == system, It will never use the input --image value.
NOT sure what is the original design, or the command might never work when command without --yaml.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These part of code are migrated from azure-cli-extensions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Greedygre yeah this code really confused me. Looking more closely I'm seeing that this behavior is a bit different than container apps (although I think functionally it's the same). The default for the registry-identity is None, so unless the user explicitly passes --registry-identity system it should function as expected, using the specified ACR image. (I did test this with a few different configurations and found this to be true)

What are your thoughts? It seems reasonable to me to remove this logic about setting the default image to HelloWorld in the case that --registry-identity system` is passed (and to more closely align with container apps create). Thoughts? If you agree, I can perform this change in a subsequent PR (I think this would technically be breaking?)


if env_vars is not None:
container_def["env"] = parse_env_var_flags(env_vars)
if startup_command is not None:
Expand Down
Loading