How to Assign a Custom Role to a Service Principal in Azure DevOps
How to Assign a Custom Role to a Service Principal in Azure DevOps Azure DevOps provides a seamless integration with Azure Active Directory (AAD) for …
In this blog, I’ll show you how to create azure container registry and build and push images from Azure DevOps pipelines.
First we create an azure container registry using terraform
resource "azurerm_container_registry" "acr" {
name = "zzlimescooter"
resource_group_name = azurerm_resource_group.rg.name
location = var.location
sku = "Standard"
admin_enabled = true
}
It will show up in the resource group like this
Once it’s done we can start pushing images to this container registry. We need to create a service connection in Azure DevOps to allow the pipeline to talk to the container registry.
Go to Azure DevOps → Project Settings → Service Connections → Docker service connection. Select the correct subscription and the container registry that just got created, in this case it will look like this.
Make sure to click on Grant access permission to all pipelines
Create a yaml file called azure-pipelines.yml in the root directory and pasted in the following code:
trigger:
branches:
include:
- test/*
- feat/*
- main
variables:
- name: repository
value: 'zzlimescooter'
- name: dockerfile
value: '$(Build.SourcesDirectory)/Dockerfile'
- name: containerRegistry
value: 'ACR_SERVICE_CONNECTION'
stages :
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build job
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: ${{ variables.repository }}
dockerfile: ${{ variables.dockerfile }}
containerRegistry: ${{ variables.containerRegistry }}
tags: $(Build.BuildId)
branches: will trigger build when the selected branches updated
variables
repository: the repository name of the ACR
dockerfile: the Dockerfile location
containerRegistry: the service connection name we just created in the above step
Name the branch test/* or feat/* will trigger run everytime the branch updates. It’s worth noting that the pipeline is not tiggered via open pull request against main, test/* and feat/*. It runs against the branch updates directly. Result of the pipeline will be:
How to Assign a Custom Role to a Service Principal in Azure DevOps Azure DevOps provides a seamless integration with Azure Active Directory (AAD) for …
How to Create App Registrations for API and Client Apps Using Azure Portal Creating app registrations for API and client apps in Azure Active …