Skip to content

Instantly share code, notes, and snippets.

@jimbo8098
Last active September 17, 2020 14:17
Show Gist options
  • Save jimbo8098/9379b473427ec57da317157d0bf74e69 to your computer and use it in GitHub Desktop.
Save jimbo8098/9379b473427ec57da317157d0bf74e69 to your computer and use it in GitHub Desktop.
Windows Docker Build with Library Variables in Azure

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: image

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment