I'm running an azure build pipeline for a dockerized application set up using an azure-pipelines.yml
file. The problem is that we require a build arg passed through to the docker build command, but the arg is blank in all circumstances (even if no build arg is provided and a default is specified in the Dockerfile
).
Snippet of azure-pipelines.yaml
(sensitive data changed only):
- task: Docker@2
displayName: build
inputs:
containerRegistry: our_container_registry
repository: $(Build.Repository.Name)
command: build
Dockerfile: '**/Dockerfile'
tags: $(Build.BuildNumber)
arguments: --build-arg BuildNumber=$(Build.BuildNumber)
Further details:
- We are using the VM image of
ubuntu-latest
to run the job - The build arg appears to be being passed through correctly as it does appear in the printout of the command that is run
- e.g. if we pass
--build-arg BuildNumber=1.2.3
as part of thearguments
property of the yaml file, we'll see--build-arg BuildNumber=1.2.3
on the printout of the command run.
- e.g. if we pass
- As can be seen from the above snippet we're not running the
buildAndPush
command that I am aware has issues with build args (publish is it's own step we're not even getting to yet). - The
Dockerfile
contains the commandRUN echo Build Number: ${BuildNumber}
which prints outBuild Number:
during the build. - Running the same build command printed out by the build step locally builds the container with no errors, and prints out the build number appropriately in the above mentioned command
I'm looking for an explanation as to how I can get the build args passed through correctly to our docker build, or if there is something we're not aware of preventing this then recommendations of other alternatives that would achieve the same ends.