Azure Functions with Continuous Deployment

A quick guide to setting up continuous deployment for Azure functions.

Continuous Deployment or Continuous Delivery allows us to deploy our application / code into the production or test based on each check in to our source control, this allows us to focus our craft and not on deployments.

Setting up CD for Azure functions is really a simple process.

Source code can be found here

Create a function

First we need some functions. I've created a simple GET function. I'm assuming you have setup functions and seen them in action already. If not check out my blog posts on Azure functions

Create a folder for your azure function.

Add a host.json file - Leave this empty for now.

{}

By default the host.json needs to have {} this leaves it empty, leaving it blank will stop the function from starting.

Create a folder for your first function. Each function should have a folder.

In this folder create 3 files.

  • project.json
{
    "frameworks": 
    {  
     "net46":
     { 
      "dependencies":
      {
        "Newtonsoft.Json": "10.0.3"
      }
     }
   }
}
  • function.json
{
    "disabled": false,
    "bindings": [
      {
        "authLevel": "anonymous",
        "name": "req",
        "type": "httpTrigger",
        "direction": "in"
      },
      {
        "name": "$return",
        "type": "http",
        "direction": "out"
      }
    ]
}

Note: I've created this function as a GET with anonymous authentication so we can call it with no keys.

  • run.csx
using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");
    
    return req.CreateResponse(HttpStatusCode.OK, "Hello there");
}

Go ahead and commit the function to your source control.

Create a function

Back onto the Azure portal. Create a new function app.

Once created head to the "Platform Features" Tab

Select Deployment options and select "Setup"

Configure sources

Azure functions allows you to deploy from different sources.

Follow the steps to select the source you want. I am going with Github.

Once setup follow the steps to add your functions source. Then click sync or make a change and push to your source control.

That's it go ahead and test the function.

When I run the test I get the hello response.

Azure makes it really easy to deploy from source control. There is the ability to add tests aswell, I'll cover that in another post.