Azure DevOps CI/CD — Creating CI for code hosted in Github

Vicky AV
4 min readJun 16, 2020

Azure DevOps CI for Spring Boot Application hosted in Github

Create Docker Image from Dockerfile & push it to Azure Container Registry

This is first among series of articles on how to build & deploy a SpringBoot Application into Azure App service using Azure DevOps CI & CD

Steps

  1. Signup for Azure DevOps portal
  2. Lets create a new CI pipeline
  3. Time to create container registry
  4. Resource group — Its mandatory
  5. Now back to our CI pipeline

Signup for Azure DevOps portal

Lets get started by creating an account in Azure DevOps site — https://azure.microsoft.com/en-in/services/devops/

I used my Github login to signup. Once signup is done, create a new organisation in Azure DevOps portal

Once organisation is created, create a new project.

For detailed step, visit here https://docs.microsoft.com/en-us/azure/devops/organizations/projects/create-project?view=azure-devops&tabs=preview-page

Lets create a new pipeline

For this tutorial, I am gonna use my User-Management-With-JWT project maintained in GitHub

Click on Pipelines -> Pipelines -> New Pipeline

Choose Pipelines from list of menu

Click the hyperlink Use the classic Editor to create a pipeline without YAML

Click on Use the classic Editor link

Select the source as Github. Choose the repo & branch details (remember you have to Authorise Azure to pull repos from your Github repo)

I chose my repo User-Management-With-JWT & branch as master

Next step is to select a template

For my User-Management-With-JWT project to work, first we need to package the application as Jar file & then build Docker Image based on it

Dockerfile available in root folder of Github repo

Since my repo is a maven project, I chose the maven template to generate the Jar file

Choose Maven as template type

Now you can see, few steps added in default by maven

Maven template added few default steps in Pipeline

Maven pom.xml step is enough for generating the jar file.

So let’s remove the other steps such as “Copy files to ${build.artifactstagingdirectory}” & “publish Artifact drop”.

Remove them by right click on the steps & choose Remove selected task(s)

Once Jar file is generated, we need to build the Docker image. In order to do it, we need to add the Docker task next to maven task

Now click on + symbol next to Agent Job 1& choose the Docker task

Click on + sign to add a task
Choose the Docker as Task
Container Registry is mandatory for the Docker image built in CI to be pushed

Time to create container registry

As you might aware, Docker images are built from Dockerfile & are pushed to container registry

Later during continuous deployment, we will be deploying the docker image from container registry

  • Go to https://portal.azure.com & search Container registries in search bar.
  • Click on Add button in Azure Container Registries portal
Add button can be seen in Top right side
Create new in Resource group can be used to create Resource group

Resource group — Its mandatory

  • Its mandatory to have a resource group to create container registry. Click on create create new in case you haven’t have one
Create Resource Group
  • Enter a new name for your Registry under Registry name & chose server Location near to your location
I created new container registry with name CiCdDemoRegistry

Click on create & you should see Deployment is complete message like below

Deployment is Complete marks successful creation of Container Registry

Now back to our CI pipeline..

  • Click on New button next to Container Registry drop down & choose Azure Container registry as Registry type
  • Choose the Azure Container Registry you created few steps back & enter a new for service connection name & hit save
  • Enter Container repository name — E.g. CiCdDemoRepo
  • Choose the Dockerfile correctly by clicking on the three dots near the Textbox
  • Click on Save & Queue to run the pipeline
Our CI ran successfully

Thats all folks !

Continue reading on next article — Azure DevOps CI/CD — Creating CD to deploy Docker Image in App Service

https://medium.com/@iamvickyav/azure-devops-ci-cd-creating-cd-to-deploy-docker-image-64bb24f6ac1d

--

--