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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With