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.
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
The following are required to complete this hands-on lab:
- An active Microsoft Azure subscription. If you don't have one, sign up for a free trial.
- An active GitHub account. If you don't have one, sign up for free .
- Execute succesfully the lab 00 .
This hands-on lab includes the following exercises:
- Exercise 1: Create an VSTS account and Project
- Exercise 2: Fork GitHub repository and create a PAT
- Exercise 3: Create a pipeline to Continuous Delivery of an Azure Function
- Exercise 4: Create custom query and use dashboard of Application Insights
Estimated time to complete this lab: 60 minutes.
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.
-
Open the Azure Portal in your browser. If you are asked to log in, do so using your Microsoft account.
-
Click New , enter Team, and click Team project
-
Click on Create
-
Enter
MyFirstProject
in Name, click Account, click Create a new account, enter a new name in URL, click OK, and click CreateIf you want to change the de deployment region or the name of team project created, click on Location .
-
Click on go to resource groupe
-
Click on your VSTS account
-
Click on Url
-
Click on MyFirstProject
-
Check you project MyFirstProject is created.
Now you have a team project ready to help you Code, Build, Release, Test your apps. Next, you need your own Github repository.
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.
-
Open the repository root on new tab https://github.com/azugfr/functions-customer-reviews, and then click on Fork or Sign in
-
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
-
If you signed in, you need to click a second time on Fork
-
Click on Clone an download. Take note of your Git Url, you will need it in Exercise 3
The forked GitHub repo allows you to commit your changes. The next step is to add an build pipeline to integrate these changes.
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.
-
Navigate to your VSTS Team project, and click on Build & Release > Builds
-
Click +New button
-
Select ASP.NET, click on Apply
-
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
-
Click on Authorize vsonline
-
Return to the Build Definiition, click on Triggers, and then select Enable continuous integration
-
Click on Tasks, and then click Process , and enter
**\ContentModerator.sln
in Path to solution or packages.configif Agent queue is not set, choose
Hosted VS2017
-
Click Save & queue > Save, and then Save
-
Click on Releases, and then **+ New definition **
-
Select Azure App Service Deployment, and click Apply
-
Enter
Dev
in Environment -
Click on Add artifact, select the build you just created in Source, and then click Add
-
Click on Continuous deployment trigger, swith On Enabled, and click on 1 phase, 1 task link
-
Click Tasks, click + New on the right of Azure Subscription
-
Click on use the automated version of the endpoint dialog
-
Enter
AzureFunction
in Name, and click OKif 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 -
Click Authorize
> A popup may appear. Login to proceed.
-
Select Function App in App type dropdown, select your
<unique_name>function
in App service name dropdownyou may have to refresh App service name after selecting App type
-
Click Save, and then OK
-
Click Builds, and click on ..., click Queue new build..., and click Queue
-
Open Build build
When the Build has succeeded
-
Click on Releases, and click ... , and Open
the release has been automatically triggered on
Dev
environment and hopefully succeeded
You have now a minimal pipeline to update your Azure Function. You can test your function work by adding some image to CustomerReviews site.
You can expand the build to also run tests
-
Click Tasks, and then Test Assemblies, and enter
**\$(BuildConfiguration)\**\*test*.dll
in Test Assemblies -
Make sure you have Colin's ALM Corner Build & Release Tools installed on your VSTS account
-
Create the following variables for your new build definitions:
- AzureWebJobsStorage from your resource group > <unique_name>
- MicrosoftVisionApiKey
- ContentModerationApiKey
- customerReviewDataDocDB
- APPINSIGHTS_INSTRUMENTATIONKEY
-
Add the
Replace Tokens
task between theBuild Solution
andTest Assemblies
tasks. This task will replace the values inlocal.settings.json
with the values in the variables. Configure the settings in this task with the following values:
You can expand the release to also create or update all the assets before deploying Azure Function App.
- In Build definition, add a new
Publish Build Artifacts
task. Set it to copy thetemplate.json
andparameters.json
available in../Provision/assets
- In Release definition, add a new
Azure Resource Group Deployment
task. 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.
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.