1
votes

I need to pass the build id parameter from Azure Devops to a dockerfile from a yaml pipeline. Unfortunately Azure Devops doesn't support the docker build-args parameter as below.

Be aware that if you use value buildAndPush for the command parameter, then the arguments property will be ignored. source

Is there any other way to pass arguments from Azure Devops through to a dockerfile?

1
Hi @cfbd, Is there any update about this ticket? Feel free to let me know if the answers could give you some help. Just a remind of thisKevin Lu-MSFT

1 Answers

1
votes

Is there any other way to pass arguments from Azure Devops through to a dockerfile?

Yes. The BuildAndPush Command doesn't support adding argument.

But the Build command support it.

You could split buildandpush into Docker build task and docker push task.

Here is an example:

steps:
- task: Docker@2
  displayName: Docker Build 
  inputs:
    command: build
    repository: $(imageRepository)
    containerRegistry: $(dockerRegistryServiceConnection)
    dockerfile: $(dockerfilePath)
    tags: 5.12.4
    arguments: '--build-arg test_val="$(build.buildid)" '
- task: Docker@2
  displayName: Docker Push
  inputs:
    command: push
    repository: $(imageRepository)
    containerRegistry: $(dockerRegistryServiceConnection)
    tags: 5.12.4

Docker Build Step Result:

enter image description here