Member-only story

Azure DevOps Pipelines — Build and Push a Docker image to AWS ECR

CJ Hewett
3 min readApr 30, 2021

--

YAML for pipeline

.azure/azure-pipelines.yml
This file is our main pipeline and only triggers on the master branch.
It uses the templates/build.yml file as a template and will use the stages defined in that file.

trigger:  
branches:
include:
- master
pr: none
stages:
- template: templates/build.yml

.azure/templates/build.yml
This template defines a stage that consists of a single job made up of two steps. The first task will essentially run a docker build to create our image with a Dockerfile in the root directory of our repo and tagging it with the name defined in the variable DOCKER_REPOSITORY_NAME and with a version equal to the pipeline build ID $(Build.BuildId).
The second task will push this image to ECR

stages:
- stage: Docker
displayName: Build & Push Docker image to AWS ECR
jobs:
- job: Build_and_Push
displayName: Build & Push Docker image
pool:
vmImage: ubuntu-latest
steps:
- task: Docker@2
displayName: Build an image
inputs:
command: build
dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
buildContext: '$(Build.SourcesDirectory)'…

--

--

CJ Hewett
CJ Hewett

Written by CJ Hewett

🛹 Skateboarder. 🏂 Snowboarder. 🏄 Websurfer. I write monthly* about Cloud/DevOps/IoT. AWS Certified DevOps Engineer and Terraform Associate

Responses (2)