When running a container build in a pipeline on Azure, it is important to remember buildAndPush does not currently support the addition of argument (see https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/docker?view=azure-devops#build-and-push ) but it is possible to build your container with arguments using the simple build command instead. For example:
- task: Docker@2
displayName: Build
inputs:
command: build
containerRegistry: $(dockerRegistryServiceConnection)
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
arguments: --build-arg SVCUSER=$(library.app.user) --build-arg SVCPASS=$(library.app.pass)
tags: |
$(tag)
In this case, the container will build with the SVCUSER/SVCPASS arguments populated by the library (in this case referred to as library.app.pass` .
The library was setup like this:
Once you pass the build arguments this way, you can just refer to them in your Dockerfile alongside default values if you wish to add them.
ARG SVCUSER=testuser
ARG SVCPASS=testpass