If you are looking for an introduction to Serverless Computing with Azure Functions, I suggest that you read my introductory blog post to Serverless Computing in this series to get you started.
Setting Up Continuous Integration
In this article let’s look at how to configure continuous integration for your Azure functions. Before you begin this tutorial you need an Azure account and a GitHub account to host your code, you can use your favorite version control system but this tutorial will be based on GitHub.
As of writing this article, Azure Functions supports the following repository types to host your code.
- Visual Studio Team Services
- Local Git Repository
- External Repository (Git/Mercurial hosted on your servers)
Building on top of what I have covered from my previous post. Let’s look at connecting the Celsius to Fahrenheit conversion function that we wrote to a GitHub repository so that we can easily manage versioning and deployment.
Setting Up the Connection to GitHub
The first step in setting up Continuous Integration is to set up the connection to your code repository, To do this go to the Function app settings on your Azure Function app and click on configure continuous integration. (See screenshot below)
Once you are in the configuration section for CI you would see the deployments window on your right, hit setup from the top menu options. (See screenshot below)
Now from the list of available repository types, select GitHub.
Now click authorize.
You will be taken to GitHub to provide authorization to Azure to pull repositories from your GitHub account, hit Authorize Application to continue.
You would see the following message once successfully authorized.
Next step is to select your repository and the branch from the available options.
Once completed you can start pushing code to GitHub for Function Apps to start auto deploying your code.
Folder structure for your function app and functions.
Note that your repository must be structured properly for things to work, the root of the branch you selected during the connection configuration serves as the root for your Function App whereas a sub-folder within this named with the exact same name as the Function (in this example HttpTriggerCSharp1) will serve as the root folder where the files would reside for that particular function. See example below.
Repository Root (Function App) │ ├───HttpTriggerCSharp1 (Function - 1) │ function.json │ run.csx │ └───HttpTriggerMyOtherFunction (Function - 2) function.json run.csx
Copy the code from run.csx, function.json and create the files in a folder named HttpTriggerCsharp1 in your repository.
Notice that you once you configure continuous integration the web interface warns you that run.csx is now read-only.
For ease of development, I have configured Visual Studio Code with the GitHub repository so that I can make changes and push to GitHub with a few clicks.
Once you commit your changes and push your code to GitHub observe how Azure function’s auto deploys your code.
So there you have it, now you have configured continuous integration for your Azure Function App.