Getting Started With Azure DevOps - Part Three

This is a series of articles to get our hands dirty with Azure Devops (previously known as VSTS)

Introduction

 
This is a series of articles to get our hands dirty with Azure DevOps (previously known as VSTS). In this article, we will focus on the concept of variables in Azure DevOps as a part of pipelines and will see its usage.
 
Please refer to the previous article – Part One and Part Two -- to understand the basics of Azure DevOps and a hands-on lab.
It will cover the following things,
  • Hands-on Lab – Code changes to pick-up value from appsettings.json
  • Hands-on Lab – Create Variables in the Release pipeline
  • Hands-on Lab - Run the Azure app to see the changes
  • Hands-on Lab - Create Variable Group + Assign to Release
  • Hands-on Lab - Run the Azure app to see the changes

Hands-on Lab - Code changes to pick-up value from appsettings.json

Steps to be followed,

Open Visual Studio and open the existing project (which is being used in previous articles). Then, open the appsettings.json file and add an “AppSettings” section with a single key and value pair.

Azure DevOps
 
Then, go to HomeController and inject Configuration in the constructor and use that object to extract values from appsettings.json and put it into the ViewBag. Please see before  where we created a normal .NET application and hosted it on Azure using build and release pipeline.

Azure DevOps

Then, go to Index.cshtml and use that ViewBag value in the paragraph on the page.

Azure DevOps
 
Here, we would like to change the values of appsettings.json through variables and get those changes reflected on the deployed site on Azure.
 

Hands-on Lab – Create Variables in the Release pipeline

Steps to be followed,

Open https://dev.azure.com/ and log in using your Azure credentials.
 
Go to the Pipeline tab, select the Release tab, and edit the existing release pipeline. Please refer to my previous articles to learn how to create a pipeline.

Azure DevOps
Go to the variable section and add a key and value pair of “Name” property in appsettings.json and then save it.

Azure DevOps
 
Create a new release and wait for it to get deployed on Azure successfully.
 

Hands-on Lab - Run the Azure app

Steps to be followed,

Open http://portal.azure.com and go to the app-service.
 
Copy the URL from the Overview section.
 
Hit the URL on the browser and wait to see the application changes and you will see that the value of Name property has been picked from the variables and not from the appsettings.json.

Azure DevOps
 

Hands-on Lab - Create Variable Group + Assign to Release

Steps to be followed,

Open https://dev.azure.com/ and log in using your Azure credentials.
 
Go to the Pipeline tab, select the Library tab, and add a new variable group and then add a variable in that which will be linked to the Release tab and click Save.

Azure DevOps
Go to the Pipeline tab and select Release tab and edit the existing release pipeline. After that, go to the Variables section and delete the pipeline variables and click on the variable group and create a link to the existing variable group created in the previous step with Release and click Save.
Azure DevOps
Create a new release and wait for the successful deployment on Azure.
 

Hands-on Lab - Run the Azure app

Steps to be followed,

Open http://portal.azure.com and go to the app-service.
 
Copy the URL from the overview section.
 
Hit the URL on the browser and wait to see the application changes and you will see that the value of Name property has been picked from the variable group and not from the appsettings.json,

Azure DevOps
 
Stay tuned for the next series of articles which would take us on a deeper dive into Azure DevOps.
 
Happy learning!