Reader small image

You're reading from  Azure Serverless Computing Cookbook. - Third Edition

Product typeBook
Published inJun 2020
PublisherPackt
ISBN-139781800206601
Edition3rd Edition
Concepts
Right arrow
Author (1)
Praveen Kumar Sreeram
Praveen Kumar Sreeram
author image
Praveen Kumar Sreeram

Praveen Kumar Sreeram is an author, Microsoft Certified Trainer, and certified Azure Solutions Architect. He has over 15 years of experience in the field of development, analysis, design, and the delivery of applications of various technologies. His projects range from custom web development using ASP.NET and MVC to building mobile apps using the cross-platform Xamarin technology for domains such as insurance, telecom, and wireless expense management. He has been given the Most Valuable Professional award twice by one of the leading social community websites, CSharpCorner, for his contributions to the Microsoft Azure community through his articles. Praveen is highly focused on learning about technology, and blogs about his learning regularly. You can also follow him on Twitter at @PrawinSreeram. Currently, his focus is on analyzing business problems and providing technical solutions for various projects related to Microsoft Azure and .NET Core.
Read more about Praveen Kumar Sreeram

Right arrow

12. Implementing and deploying continuous integration using Azure DevOps

In this chapter, you'll learn about the following topics:

  • Continuous integration—creating a build definition
  • Continuous integration—queuing a build and triggering it manually
  • Continuous integration—configuring and triggering an automated build
  • Continuous integration—executing unit test cases in the pipeline
  • Creating a release definition
  • Triggering a release automatically
  • Integrating Azure Key Vault to configure application secrets

Introduction

As a software professional, you may be aware of different software development methodologies that are followed across the industry. Irrespective of the methodology being followed, there will be multiple environments, such as development, staging, and production, where the application life cycle needs to be followed, with these critical stages related to development:

  1. Develop the application based on the requirements.
  2. Build the application and fix any errors.
  3. Deploy/release the package to an environment (development/staging/production).
  4. Test against the requirements.
  5. Promote the release to the next environment (from development to staging and staging to production).

    Note

    For the sake of simplicity, the initial stages, such as requirement gathering, planning, designing, and architecture, are excluded, just to emphasize the stages that are relevant to this chapter.

For each change made to the software, we need to build and deploy the application...

Continuous integration—creating a build definition

In this recipe, we will learn how to configure continuous integration by creating a build definition. A build definition is a set of tasks that are required to configure an automated build of software. In this recipe, we will perform the following:

  1. Create the build definition template.
  2. Provide all the inputs required for each of the steps to create the build definition.

Getting ready

Perform the following prerequisites:

  1. Create an Azure DevOps account.
  2. Create a project by choosing Git, as shown in Figure 12.2:
    Creating a private Azure DevOps project with Git version control
Figure 12.2: Creating a private Azure DevOps project with Git version control

How to do it…

In order to create the build definition, we'll have to perform the following steps:

  1. Navigate to the Pipelines tab in the Azure DevOps account, click on Pipelines, and choose Create Pipeline to start the process of creating a new build definition, as shown in Figure...

Continuous integration—queuing a build and triggering it manually

In the previous recipe, you learned how to create and configure a build definition. In this recipe, you will learn how to trigger a build manually and understand the process of building an application.

Getting ready

Before we begin, make sure that you have done the following:

  • Configured the build definition as mentioned in the previous recipe.
  • Checked all of your source code into the Azure DevOps team project.

How to do it...

Perform the following steps:

  1. Navigate to the build definition named AzureFunctions-CI, click on the Edit button, and then click on the Queue button available on the right-hand side, as shown in Figure 12.11:
    Clicking on the Queue button
    Figure 12.11: Azure DevOps—build pipelines—the Queue button
  2. In the Azure Pool for AzureFunctions-CI pop-up window, make sure that the vs2017-win2016 option is chosen in the Agent Specification drop-down list in Visual Studio 2017 or 2019 and click on the Queue button, as shown in Figure 12.12:
    Running a pipeline
    Figure 12.12: Azure DevOps—build pipelines—running a pipeline

    Note

    At the time of writing, the VS 2019 option is not available. While reading, if the VS 2019 option becomes available, feel free to choose that.

  3. In just a few moments, the build will be queued and the message will be displayed, as shown in Figure 12.13:
    Viewing progress of the build process
    Figure 12.13: Azure DevOps—build pipelines—viewing progress
  4. After a few moments, the build process will...

Continuous integration—configuring and triggering an automated build

For most applications, it might not make sense to perform manual builds in Azure DevOps. It would make sense if we can configure continuous integration by automating the process of triggering the build for each check-in/commit done by the developers.

In this recipe, you will learn how to configure continuous integration in Azure DevOps for the team project and also trigger an automated build by making a change to the code of the HTTP trigger Azure function that we created in Chapter 4, Developing Azure functions using Visual Studio.

How to do it…

Perform the following steps:

  1. Navigate to the AzureFunctions-CI build definition by clicking on the Edit button, as shown in Figure 12.17:
    Editing a pipeline
    Figure 12.17: Azure DevOps—build pipelines—editing a pipeline
  2. Once inside the build definition, click on the Triggers menu, as shown in Figure 12.18:
    Enabling continuous integration in the Triggers tab
    Figure 12.18: Azure DevOps—...

Continuous integration—executing unit test cases in the pipeline

One of the most important steps in any software development methodology is to write automated unit tests to validate the correctness of our code. It is also important that we run these unit tests every time the developer commits new code, to provide test code coverage.

In this recipe, we will learn how to incorporate the process of building the unit tests that we developed in the Developing unit tests for Azure functions with HTTP triggers recipe of Chapter 5, Exploring testing tools for Azure functions.

How to do it…

In this recipe, we are going to add a new task to the pipeline that runs the unit test cases. Perform the following steps:

  1. Edit the AzureFunctions-CI build definition and add the .NET Core task as shown in Figure 12.22:
    Adding a .NET Core task
    Figure 12.22: Azure DevOps—build pipelines—adding a new task
  2. Once the task is added, change the following attributes of the task:

    Display Name...

Creating a release definition

Now that we know how to create a build definition and trigger an automated build in Azure DevOps pipelines, our next step is to release or deploy the package to an environment where the project stakeholders can review it and provide feedback. In order to do that, we need to create a release definition in the same way that we created the build definitions.

Getting ready

Before working on this recipe, please make sure you have created the build definition and also ensure that you have run it successfully at least once.

How to do it…

To release and deploy the package to an environment, we'll perform the following steps:

  1. Navigate to the Releases tab, as shown in Figure 12.26, and click on the New pipeline button:
    Creating a new pipeline
    Figure 12.26: Azure DevOps—release pipelines—New Pipeline
  2. The next step is to choose a release definition template. In the Select a template pop-up window, select Deploy the function app to Azure Functions...

Triggering a release automatically

In this recipe, you will learn how to configure continuous deployment for an environment. In your project, you can configure development, staging, or any other pre-production environment and configure continuous deployment to streamline the deployment process.

In general, it is not recommended to configure continuous deployment for a production environment. However, this might depend on various factors and requirements. Be cautious and think about various scenarios before configuring continuous deployment for a production environment.

Getting ready

Download and install the Postman tool if it's not installed yet.

How to do it…

To configure continuous deployment, we'll perform the following steps:

  1. By default, the releases are configured to be pushed manually. Let's configure continuous deployment by navigating back to the Pipeline tab and clicking on the Continuous deployment trigger button, as shown in Figure...

Integrating Azure Key Vault to configure application secrets

One of the major parts of any project is handling secrets in an efficient manner to adhere to organization-wide security guidelines. It's not advised to maintain secrets (such as passwords) in code or in files that are accessible to developers or any other stakeholders. In fact, these days, all the production environment details are only accessible by a few people and the secrets are managed by various systems. One such system in Azure is Key Vault. In this recipe, we'll learn how to leverage Key Vault to manage a secret that can be accessed by the code in a function app.

How to do it…

In this recipe, we will work on the following steps:

  1. Creating a secret in the Key Vault service.
  2. Configuring the Azure DevOps release pipeline.
  3. Configuring the access policy.

Creating a secret in the Key Vault service

In this section, we will create a Key Vault service that can be used to manage...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Azure Serverless Computing Cookbook. - Third Edition
Published in: Jun 2020Publisher: PacktISBN-13: 9781800206601
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Praveen Kumar Sreeram

Praveen Kumar Sreeram is an author, Microsoft Certified Trainer, and certified Azure Solutions Architect. He has over 15 years of experience in the field of development, analysis, design, and the delivery of applications of various technologies. His projects range from custom web development using ASP.NET and MVC to building mobile apps using the cross-platform Xamarin technology for domains such as insurance, telecom, and wireless expense management. He has been given the Most Valuable Professional award twice by one of the leading social community websites, CSharpCorner, for his contributions to the Microsoft Azure community through his articles. Praveen is highly focused on learning about technology, and blogs about his learning regularly. You can also follow him on Twitter at @PrawinSreeram. Currently, his focus is on analyzing business problems and providing technical solutions for various projects related to Microsoft Azure and .NET Core.
Read more about Praveen Kumar Sreeram