Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am using Azure Devops to build and push my Docker image. How can I pass arguments while doing buildAndPush using Docker task?

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?

like image 345
Ajinkya Avatar asked Feb 18 '20 18:02

Ajinkya


People also ask

How do I deploy a Docker image using Azure DevOps?

Sign in to your Azure DevOps organization and navigate to your project. Select Pipelines, and then New Pipeline. Select GitHub when prompted for the location of your source code, and then select your repository. Select the Docker: build and push an image to Azure Container Registry pipeline template.

How do I publish a Docker image as an artifact in Azure DevOps?

Steps: Add task docker->switch the task version to 0->select the option Run a Docker command , then we could run the docker save command, check the pic below. Is there any better way of doing this apart from saving an image. We recommend that you use this to upload the docker image as an artifact.

How is a docker file created on the Azure DevOps pipeline?

To do that in Azure DevOps, click on Project Settings –> Service connections –> New service connection. This opens a pop-up where you select Docker Registry. On the next page, select Docker Hub as your Registry type, enter your Docker ID, password and set a name for your connection. Then click Verify and save.


1 Answers

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
like image 103
Ajinkya Avatar answered Sep 17 '22 17:09

Ajinkya