azureazure-cliazure-acr

Azure CLI - acb.yaml does not exist


I am trying to create a scheduled ACR task to delete old images from storage using this command:

PURGE_CMD="acr purge --filter 'worker:.*' --untagged --ago 1d"
 az acr task create --name remove_old_images_worker --cmd "$PURGE_CMD" --schedule
 "0 0 * * *" --registry registry --context /dev/null

But it returns me an error with this:

acb.yaml does not exist.

And what is also interesting is that it worked for a similar task just a couple of days ago.


Solution

  • After some investigation, I solved this problem using Terraform as follows:

    resource "azurerm_container_registry_task" "acr_purge_task" {
      name                  = "scheduledAcrPurgeTask"
      container_registry_id = azurerm_container_registry.registry.id
      platform {
        os           = "Linux"
        architecture = "amd64"
      }
      encoded_step {
        task_content = <<EOF
        version: v1.1.0
        steps:
        - cmd: acr purge --filter '.*:^((?!prod|dev).)*$' --untagged --ago 7d
        disableWorkingDirectoryOverride: true
        timeout: 3600
        EOF
      }
      agent_setting {
        cpu = 2
      }
      timer_trigger {
        name     = "t1"
        schedule = "0 0 * * Tue"
        enabled  = true
      }
    }