0

I want to execute some bash scripts with azure task, the task is created successfully but it doesn't do anything and also it doesn't log anything, it seems that the script never gets executed, here is the task that i create :

---
name: archive
platform:
  os: linux
steps:
  - cmd: |
      REGISTRY=***
      PROD_REPO=***
      ARCHIVE_REPO=***
      echo "Logging into ACR..."
      az acr login --name $REGISTRY
      LATEST_TAG=$(az acr manifest list-metadata \
        --registry $REGISTRY --name $PROD_REPO --orderby time_desc \
        --query [0].tags[0] --output tsv)
      echo "LATEST_TAG: $LATEST_TAG"
      ALL_TAGS=$(az acr manifest list-metadata --registry $REGISTRY \
        --name $PROD_REPO --output tsv)
      for TAG in $ALL_TAGS; do
        if [ \"$TAG\" != \"$LATEST_TAG\" ]; then
          echo "Archiving tag $TAG..."
          az acr import --name $REGISTRY --source "$REGISTRY/$PROD_REPO:$TAG" \
            --repository $ARCHIVE_REPO --force
      done
      echo "Archiving process completed."
context: /dev/null
registry: ***

I create the task by the following command :

az acr task create --file archive.yaml --registry *** --name archive --schedule "* * * * *"  --context /dev/null

Task is created but when i look at the logs it just says task executed successfully but it does nothing and also doesn't print anything for echo expresssion.

enter image description here

I also tried a simple echo script, but that one doesn't work either:

---
name: archive-optimizer
platform:
  os: linux
steps:
  - cmd: |
      echo "Test..."
context: /dev/null
registry: ofsav

Update:

I added version as follows and now it prints logs:

version: v1.1.0
steps:
  - cmd: |
      REGISTRY=***
      PROD_REPO=***
      ARCHIVE_REPO=***
      echo "Logging into ACR..."
      az acr login --name $REGISTRY
      LATEST_TAG=$(az acr manifest list-metadata \
        --registry $REGISTRY --name $PROD_REPO --orderby time_desc \
        --query [0].tags[0] --output tsv) || { echo "Failed to get latest tag"; exit 1; }
      echo "LATEST_TAG: $LATEST_TAG"
      ALL_TAGS=$(az acr manifest list-metadata --registry $REGISTRY \
        --name $PROD_REPO --output tsv) || { echo "Failed to get all tags"; exit 1; }
      echo "ALL_TAGS: $ALL_TAGS"
      for TAG in $ALL_TAGS; do
        if [ \"$TAG\" != \"$LATEST_TAG\" ]; then
          echo "Archiving tag $TAG..."
          az acr import --name $REGISTRY --source "$REGISTRY/$PROD_REPO:$TAG" \
            --repository $ARCHIVE_REPO --force || { echo "Failed to archive tag $TAG"; exit 1; }
        fi
      done
      echo "Archiving process completed."

Now it gives another error:

az command not found

While based on the following document az command should be recognized: Yaml file for acr task

1 Answer 1

1

The az command not being recognized within the ACR task indicates that the Azure CLI is not available in the task's execution environment.

enter image description here

  • ACR tasks use lightweight containerized environments that may not have az pre-installed.

Here I have signed-in my azure acc initially that you can check below.

enter image description here

I have base image to test Azure CLI here is the YAML file.

version: v1.1.0
name: archive-optimizer
platform:
  os: linux
steps:
  - cmd: |
      echo "Installing Azure CLI..."
      curl -sL https://aka.ms/InstallAzureCLIDeb | bash
      echo "Azure CLI installed successfully."
      REGISTRY=***
      PROD_REPO=***
      ARCHIVE_REPO=***
      echo "Logging into ACR..."
      az acr login --name $REGISTRY
      LATEST_TAG=$(az acr manifest list-metadata \
        --registry $REGISTRY --name $PROD_REPO --orderby time_desc \
        --query [0].tags[0] --output tsv) || { echo "Failed to get latest tag"; exit 1; }
      echo "LATEST_TAG: $LATEST_TAG"
      ALL_TAGS=$(az acr manifest list-metadata --registry $REGISTRY \
        --name $PROD_REPO --output tsv) || { echo "Failed to get all tags"; exit 1; }
      echo "ALL_TAGS: $ALL_TAGS"
      for TAG in $ALL_TAGS; do
        if [ "$TAG" != "$LATEST_TAG" ]; then
          echo "Archiving tag $TAG..."
          az acr import --name $REGISTRY --source "$REGISTRY/$PROD_REPO:$TAG" \
            --repository $ARCHIVE_REPO --force || { echo "Failed to archive tag $TAG"; exit 1; }
        fi
      done
      echo "Archiving process completed."
context: /dev/null
registry: ofsav
Sign up to request clarification or add additional context in comments.

3 Comments

Chikam Thanks for your answer, i'll give it a try soon, isn't installing CLI for each run harmful? i think that command runs in a container and that container gets disposed immediately after each finishing, if it's so, then it should be safe.
I still get the same error, azure cli is installed but still complaining about az command.
It seems like the linux image does not allow installation of anything: apt-get: command not found

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.