acr icon indicating copy to clipboard operation
acr copied to clipboard

Error running ACR task: failed to unmarshal task before running: failed to deserialize task and validate: yaml: line 4: could not find expected ':'

Open geoffreygeslin opened this issue 5 years ago • 6 comments

Describe the bug I want to create an acr task to trigger new builds of my "app" image after base image updates inside same Azure registry. As stated in the tutorial, I need to run my task once so it can track the base image dependency...

When I run my task I get the following error:

failed to unmarshal task before running: failed to deserialize task and validate: yaml: line 4: could not find expected ':'

Run ID: cb6 failed after 9s. Error: failed during run, err: exit status 1

To Reproduce

  1. Create the task :
az acr task create `
     --registry $ACR_NAME `
     --name tasktestacrtask01 `
     --image  'testacrtask:tasktestacrtask01{{.Run.ID}}' `
     --file Dockerfile `
     --arg IMAGE=$ACR_NAME.azurecr.io/is-serverbase `
     --context /dev/null `
    --platform windows
  1. Run the task :
az acr task run --registry $ACR_NAME --name tasktestacrtask01
Queued a run with ID: cb6
Waiting for an agent...
2020/04/21 20:01:14 Alias support enabled for version >= 1.1.0, please see https://aka.ms/acr/tasks/task-aliases for more information.
failed to unmarshal task before running: failed to deserialize task and validate: yaml: line 4: could not find expected ':'`

Run ID: cb6 failed after 9s. Error: failed during run, err: exit status 1

If this can help, first lines of my dockerfile look like this:

# escape=`

# some comments
ARG IMAGE=nameofmyregistry.azurecr.io/is-serverbase
ARG VERSION=4.7.2-windowsservercore-ltsc2019
FROM $IMAGE:$VERSION

Expected behavior I want my task to run with success and monitor further base image updates.

What am I missing here ?

Any relevant environment information

  • OS: Windows
  • Azure CLI version : 2.0.81
  • Docker version 19.03.2, build 6a30dfc
  • Datetime (UTC) when the issue occurred : April 21, 2020 20:30:00 (UTC)

geoffreygeslin avatar Apr 21 '20 21:04 geoffreygeslin

@geoffreygeslin, it looks you used a Dockerfile as a multi-step task file. They're different. For you case, you first need to push the source code including Dockerfile to GitHub or Azure DevOps repository and then run the the command like the following to create the task.

az acr task create `
     --registry $ACR_NAME `
     --name tasktestacrtask01 `
     --image 'testacrtask:tasktestacrtask01{{.Run.ID}}' `
     --file Dockerfile `
     --arg IMAGE=$ACR_NAME.azurecr.io/is-serverbase `
     --context https://github.com/user/repo.git#branch:folder `
     --platform windows

Multi-step task provides the features which allow you do more stuff beyond docker build. If you are interested, you can see how to use a single Dockerfile OR multi-step task file to build the same project.

https://github.com/Azure-Samples/acr-tasks/tree/master/build-aspnetapp

northtyphoon avatar Apr 21 '20 23:04 northtyphoon

@northtyphoon Thank you for your quick reply.

As my acr contains :

  • the base image to monitor,
  • the build context of my "app" image (I used 'acr build')

... I thought my scenario would work. Can this case be condidered to be covered by acr tasks someday ?

For now, I do prefer to use a multi-step task file rather than changing our repository.

Looking at the acb.yaml file in the sample, I'm wondering which parts are mandatory ? Can I start with a most simple 2 steps file, only containing "build" and "push" ?

Also, as my base image is already pushed in my registry, can you confirm I can skip the "az acr import" prerequisite ?

geoffreygeslin avatar Apr 22 '20 09:04 geoffreygeslin

You only need "build" and "push". You don't need "import" if you already have the base image in your registry.

northtyphoon avatar Apr 24 '20 07:04 northtyphoon

I successfully run an multi step build with "az acr run" and a yaml file.

I'm wondering how to pass custom build args on "az acr run" command ? In the documentation, I can't fin any "build-arg" argument for acr run, whereas it is supported on "az acr build"... Also, how should I decribe such custom build args in the yaml file ? Can i use the $ syntax for variables of my own ?

Now that I have a multistep build with a valid yaml file, i will follow the rest of this tutorial : https://docs.microsoft.com/en-us/azure/container-registry/container-registry-tutorial-base-image-update#build-the-application-container

Could you please explicitly confirm I do NOT need any git or az devops repo to get my "multi-steps" az task auto-triggered ?

geoffreygeslin avatar Apr 30 '20 11:04 geoffreygeslin

Yes here is an example of a Docker file

ARG REGISTRY=myregistry.azurecr.io
ARG IMAGE=hello-world:latest
FROM $REGISTRY/$IMAGE

Here it the acb.yaml that you can create the task with using the $Registry alias for build args.

version: v1.1.0
steps:
  - build: -t $Registry/hello-world:$ID -f Dockerfile  --build-arg REGISTRY=$Registry .
  - push: ["$Registry/hello-world:$ID"]

sample here - https://github.com/sajayantony/dockerfiles/tree/master/docker-build-args

sajayantony avatar May 06 '20 23:05 sajayantony

Any Updates on this ?

darkweb-123 avatar Aug 31 '21 08:08 darkweb-123

Closing as this has been inactive for over three months. Please open a support ticket with our team for assistance.

terencet-dev avatar Nov 17 '22 20:11 terencet-dev