This is the first part in a series demonstrating how to setup continuous deployment of an Azure Functions App using Azure DevOps build and release pipelines.
In this series we’ll explore (among other things) how to:
- Build an Azure Functions App when code is pushed to GitHub
- Run unit tests as part of the build
- Create multiple Azure Pipeline artifacts
- Release to a test Function App environment in Azure
- Run automated functional end to end tests
- Release to a production Function App environment in Azure
- Run smoke tests after a production deployment
…in addition to a whole host of other things such as: YAML build files, Azure Pipeline variables, setting Azure Function app settings from an Azure release pipeline, and using post-deployment gates.
An Overview of Azure DevOps
Azure DevOps is a collection of cloud services to facilitate team DevOps practices and includes:
- Azure boards
- Azure Pipelines
- Azure repos
- Azure test plans
- Azure Artifacts
In this series we’ll be focussing on Azure Pipelines to build, test, and deploy the Function App automatically when new changes are pushed to GitHub.
InvestFunctionApp Overview
The demo code for these demos can be found on GitHub.
The InvestFunctionApp contains a number of functions that allow the investing of money in a portfolio. The initial entry point is a HTTP-triggered function that allows the investor id to be specified along with how much to add to the investors portfolio.Depending on the investors target allocations, the amount will be investing in either bonds or shares.
There are 4 functions involved in this workflow:
- Portfolio function: HTTP trigger, starts the workflow, creates a queue message
- CalculatePortfolioAllocation function: queue trigger from the output of (1), calculates where to invest and writes to either buy-stocks queue (3) or buy-bonds queue (4)
- BuyStocks function: triggered from buy-stocks queue, simulates buying stocks and updates the investor’s portfolio in Azure Table storage
- BuyBonds function: triggered from buy-bonds queue, simulates buying bonds and updates the investor’s portfolio in Azure Table storage
The app is designed to demonstrate the facilities of Azure Pipelines and is simplified in many ways including minimal error checking, auditing, transactions, security, etc.
Azure DevOps Build Pipeline
The build Azure Pipeline will be automatically triggered from changes pushed to the GitHub repository.
The build pipeline will have the following steps:
- Build the solution
- Run unit tests
- Publish test results
- Package the Function App
- Publish the packaged Function App as a build artifact
- Copy the functional end-to-end tests
- Publish the functional end-to-end tests as a separate build artifact
Assuming all these step run without error, the two build artifacts can be passed to/used by the release pipeline.
Azure DevOps Release Pipeline
The release pipeline will be triggered automatically when the build pipeline completes without error.
The following diagram shows what the resulting release pipeline will look like:
The release pipeline will:
- Deploy the Function App to a test Function App in Azure
- Run functional end-to-end tests (written in xUnit.net) against this test deployment
- If the tests in (2) pass, deploy to production
- After deploying to production, call a smoke test function to verify the deployment was successful
In the next part of this series we’ll create Function Apps, signup to Azure DevOps, create a new DevOps project, and take a closer look at the demo function app.
If you want to fill in the gaps in your C# knowledge be sure to check out my C# Tips and Traps training course from Pluralsight – get started with a free trial.
SHARE: