Skip to content

Latest commit

 

History

History
 
 

03 - Continuous Delivery

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Create a continuous delivery pipeline


Overview

Visual Studio Team Services (VSTS) helps helps automate ans secure the delivery pipeline of your applications. In lab 00, we used the intern deployment engine tool of Azure Kudu. It's a great tool to start with but comes with limitations.

In this lab, you will create a build pipeline to automatically build, test, package and deploy the Azure Function that check Image and moderate text for the CustomerReviews site. And use Application Insights to follow the health of solution and results of the reviews.

Objectives

In this hands-on lab, you will learn how to:

  • Create a Continuous Deployment of an Azure Function
  • Use a custom telemetry for Application Insights

Prerequisites

The following are required to complete this hands-on lab:


Exercises

This hands-on lab includes the following exercises:

Estimated time to complete this lab: 60 minutes.

Exercise 1: Create an VSTS account and Project

The first step in creting a continuous pipeline is to create an VSTS account and a Team Project. In this exercise, you will create the a new account and through Azure Portal.

  1. Open the Azure Portal in your browser. If you are asked to log in, do so using your Microsoft account.

  2. Click New , enter Team, and click Team project

    create Team Project

  3. Click on Create

    create team project

  4. Enter MyFirstProject in Name, click Account, click Create a new account, enter a new name in URL, click OK, and click Create

    If you want to change the de deployment region or the name of team project created, click on Location .

create team project

  1. Click on go to resource groupe

    go to resource group

  2. Click on your VSTS account

    click VSTS account

  3. Click on Url

    build and deployment

  4. Click on MyFirstProject

    open projects

  5. Check you project MyFirstProject is created.

    first project created

Now you have a team project ready to help you Code, Build, Release, Test your apps. Next, you need your own Github repository.

Exercise 2: Fork GitHub repository and create a PAT

Once you have created an VSTS account and team project, you can build a project from any git repository. To enable continuous trigger for each commit on GitHUb repository, you need to be an owner on the repository. In this exercise, you will fork this repository to your account on which you will be an owner.

  1. Open the repository root on new tab https://github.com/azugfr/functions-customer-reviews, and then click on Fork or Sign in

    Fork the git repo

  2. Click on Enter your username and password, and then click Sign in

    If you don't have an GitHub account, click on Create an account to create one

    GitHub sign in

  3. If you signed in, you need to click a second time on Fork

    Fork in progress

  4. Click on Clone an download. Take note of your Git Url, you will need it in Exercise 3

Git repository url

The forked GitHub repo allows you to commit your changes. The next step is to add an build pipeline to integrate these changes.

Exercise 3: Create a pipeline to set Continuous Delivery of an Azure Function

The VSTS team project you created in Exercise 1 and the GitHub repo you forked in Exercise 2 will helps you build, test and deploy the Azure Function in ContentModerator solution to the Azure Function App you provisionned in [lab 00](../00 - Provision resources and Reset). In this exercise, you will create a minimal pipeline with a build and a release definitions to continuously deploy your change on the Azure Function.

  1. Navigate to your VSTS Team project, and click on Build & Release > Builds

    Navigate to Build & Release

  2. Click +New button

    create new build

  3. Select ASP.NET, click on Apply

    select ASP.NET

  4. Click on Get sources, Select GitHub, enter connection of your fork GitHub repository created in exercise 2, and then click on Authorize using OAuth

    if nothing happen, your browser may blocking popup windows, authorize them to continue. And click on Authorize using OAuth

    Github repo

  5. Click on Authorize vsonline

    Authorize vsts to access repos

  6. Return to the Build Definiition, click on Triggers, and then select Enable continuous integration

    enable continuous integration

  7. Click on Tasks, and then click Process , and enter **\ContentModerator.sln in Path to solution or packages.config

    if Agent queue is not set, choose Hosted VS2017

    edit solutions path

  8. Click Save & queue > Save, and then Save

    Save build definitionbuild folder

  9. Click on Releases, and then **+ New definition **

    new release

  10. Select Azure App Service Deployment, and click Apply

select app service deployment

  1. Enter Dev in Environment

    environment name

  2. Click on Add artifact, select the build you just created in Source, and then click Add

    add build artifact

  3. Click on Continuous deployment trigger, swith On Enabled, and click on 1 phase, 1 task link

    enable continuous deployment

  4. Click Tasks, click + New on the right of Azure Subscription

    New Azure subscription

  5. Click on use the automated version of the endpoint dialog

    use automated view

  6. Enter AzureFunction in Name, and click OK

    if dropdown Subscrition is empty if you do not see the subcription used for lab 00, your vsts account is not linked to the Azure subscription. You can link your VSTS account to Azure subscription Or use preceding dialog and follow instructions of creating a service principal and Service endpoints. Add Contributor role to your Service principal on Azure Function App

    create Azure end point

  7. Click Authorize

> A popup may appear. Login to proceed.

authorize subscription

  1. Select Function App in App type dropdown, select your <unique_name>function in App service name dropdown

    you may have to refresh App service name after selecting App type

    select function

  2. Click Save, and then OK

    Save releaseSave release

  3. Click Builds, and click on ..., click Queue new build..., and click Queue

    queue buildqueue build

  4. Open Build build

    open build

    When the Build has succeeded

    Build succeeded

  5. Click on Releases, and click ... , and Open

    open release

    the release has been automatically triggered on Dev environment and hopefully succeeded

    Release succeeded on Dev

    You have now a minimal pipeline to update your Azure Function. You can test your function work by adding some image to CustomerReviews site.

Expand build to run tests

You can expand the build to also run tests

  1. Click Tasks, and then Test Assemblies, and enter **\$(BuildConfiguration)\**\*test*.dll in Test Assemblies

  2. Make sure you have Colin's ALM Corner Build & Release Tools installed on your VSTS account

  3. Create the following variables for your new build definitions:

    • AzureWebJobsStorage from your resource group > <unique_name>
    • MicrosoftVisionApiKey
    • ContentModerationApiKey
    • customerReviewDataDocDB
    • APPINSIGHTS_INSTRUMENTATIONKEY
  4. Add the Replace Tokens task between the Build Solution and Test Assemblies tasks. This task will replace the values in local.settings.json with the values in the variables. Configure the settings in this task with the following values:

    • sourcePath: ContentModeratorFunction/bin/$(BuildConfiguration)

    • filePattern: local.settings.json

    • tokenRegex: (\w+)

    • Queue a new build run - the build summary should show the two tests passed:

(Advanced) Expand pipeline to automate resource deployment

You can expand the release to also create or update all the assets before deploying Azure Function App.

  1. In Build definition, add a new Publish Build Artifacts task. Set it to copy the template.json and parameters.json available in ../Provision/assets
  2. In Release definition, add a new Azure Resource Group Deploymenttask. Set it to update your assets as detailed in automate resource deployment of Azure Function

The work of writing, configuring and deploy the Azure Function is complete.

Summary

In this hands-on lab you learned how to:

  • Create a VSTS account and a new Team project
  • Create a fork of a Github repository and a new PAT to access this repository
  • Create a new pipeline with a Build and a Release definitions to continuously deliver an Azure Function

This is just one example of how you can leverage VSTS and Application Insights. Experiment with other application deployment, you may want to add CustomerReviews site alonside the Azure Function. You could also leverage Azure Web apps capabilities like Slots to launch integrations tests before, or add an intermediate environment before production one like in this blog post. You could also explore Azure DevOps Projects to rapidly kickstart your project.