16
votes

I have created a pipeline to build a Docker image and push it to my container registry. I am using Docker task for doing this (buildAndPush command). Here is a YAML snippet of the 'Build and Push' step:

- task: Docker@2
  displayName: Build and Push
  inputs:
    command: buildAndPush
    containerRegistry: dockerRegistryServiceConnection1
    repository: contosoRepository
    tags: latest
    arguments: --label buildtype=nightly

The arguments input is ignored by the task. How can I pass arguments to the Docker command?

1

1 Answers

41
votes

When using buildAndPush command in Docker task, the arguments are ignored. Since this is a combination of two Docker commands, the arguments input becomes ambiguous.

If you want to add some arguments to your build command, you can split build and push into two separate steps like this:

- task: Docker@2
  displayName: Build
  inputs:
    command: build
    containerRegistry: dockerRegistryServiceConnection1
    repository: contosoRepository
    tags: latest
    arguments: --label buildtype=nightly

- task: Docker@2
  displayName: Push
  inputs:
    command: push
    containerRegistry: dockerRegistryServiceConnection1
    repository: contosoRepository
    tags: latest