Docker with Azure DevOps

Sample YAML file to build and push Docker image with Azure Pipelines.

trigger:
- main

pool:
  vmImage: ubuntu-latest

variables:
  buildConfiguration: 'Release'

steps:
- script: dotnet restore
  displayName: 'Restore'

- script: dotnet build -c $(buildConfiguration) --no-restore
  displayName: 'Build'

- script: dotnet test -c $(buildConfiguration) --no-build
  displayName: 'Test'

- script: dotnet publish '[csproj location]' -c $(buildConfiguration) -o '[publish folder]'
  displayName: 'Publish'

- script: docker build -f '[Dockerfile location]' -t [server/image-name:tag] .
  displayName: 'Create docker image'

- script: |
    docker login [server] -u [user name] -p $(ACR-PWD) # This is from pipeline variable
    docker push [server/image-name:tag]
    docker logout [server]
  displayName: 'Push docker image'

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s