6 min read

Receive Kudu and Web App deployment information through Azure Logic Apps

 

I absolutely love Logic Apps. They're quick, easy to configure and get the job done. To be honest I was a bit cautious when they first came out as I was never the "design first" kinda guy. They have proven me wrong and for most automation challenges there is a Logic App somewhere in the solution. Don't over-complicate things, keep it simple :)

When it comes to deploying your solutions to Azure Web Apps, there are number of options when it comes to source control. Are you pulling your sources from Github, Bitbucket, Dropbox or just uploading your code through FTP? If you're managing your deployment through Azure Web Apps (and the new Deployment Center) and you're not using Azure Pipelines then you might not receive the notifications where and when you want them. For instance: Azure DevOps provides great notifications on builds, releases and pretty much whatever you configure. Deployment Center right now, does not.

When you set up your source control you can choose one of two available build providers: "App Service Kudu Build Server" and "Azure Pipelines (preview)". Both have different use cases, depending on the complexity you require. For quick and simple deployments I usually go with the Kudu Build Server.

Once configured the Deployment Center gives a nice overview of your deployments and you can request some pretty detailed logging coming from Kudu. But sometimes I just want those deployment messages in my E-Mail. For instance when it's an App I am not managing or when I'm not actively participating in a team, I'd still like to get notified. Now you could generate some information by creating an alert based on the Azure Activity logging but all that will give you is a very basic notification that someone or something initiated a deployment on the Web App. It doesn't give you the information that Kudu can.

Kudu comes with the ability to configure pre and post deployment webhooks. That sounds like something we can use.

Configuring the notifications

As a quick fix, I went for the Logic App approach as Logic Apps can be initiated through an HTTP Trigger. If I want more than just an E-Mail I can simply add other branches in my Logic App to send data to multiple targets.

First make sure you have a Web App with the Build and Deployment configuration set through Deployment Center.

Create a new Logic App and a big welcome blade should pop up. Go with a common trigger and select "When a HTTP request is received".

 

Once the designer has initiated it should show an empty HTTP trigger. For now this will do and just add a new step which is "Send an E-Mail". Configure a provider to your liking - I went with Outlook.com. You can ignore the message about the URL for now.    

 

 

Because we want to do some debugging and we don't exactly know the content that Kudu is sending, let's first send the body. (If it doesn't pop up right away, you can configure this by typing "Body" in the Dynamic content box and add it). Then create a connection at the bottom of the window and it should prompt for your credentials.

Note that in production environments you might want have a dedicated E-Mail account for this.

 

Once configured, hit "Save" and copy the "HTTP Post URL" which should now be generated and available.

Go back to your Web App and open the Kudu Console (Web App --> Development Tools --> Advanced Tools"). Once the Kudu console has loaded, navigate to "Webhooks".

What we need right now is information "Post deployment", so all you need to do is paste the "HTTP Post URL" you just copied. Just paste in the "Subscriber URL" box and the URL. Your configuration should look similar to the following:

 

Once subscribed, go back to the Deployment Center and click "Sync" to initiate a synchronization and essentially re-deploy the latest version to your Web App. This will trigger the Post Deployment Webhook that we just configured and you should have received an E-Mail. But... it looks a bit "JSON-ish". We'll get to that.

 

Your Logic App should show at least one succesful run by now.

 

Now if you're configuring this just to notify yourself and you're fine with reading JSON then this should be enough for you. But sometimes you just want to include less tech-savy folks and let's be honest, they'll probably move it to the spam folder the way it looks right now.

We can use the received data as sample data. Let's go back to he logic app and make a few changes to the layout.

When you select the HTTP trigger, it will have an option "use sample payload to generate schema". How convenient, we just received sample data over E-Mail!

 

Clicking on the "use sample payload to generate schema" option should provide you with a new input box. Copy and paste your contents from the E-mail. Note that you can also get this data by browsing to the run history of the logic app and copy the contents of "body": { }

 

 

Make sure you copy and paste only the body of the E-Mail and click "Done". The Logic App will now generate a schema for you and provide you with objects that you can select from the Dynamic content when configuring the E-Mail body.  

   

If you want to configure it all in one go when creating the logic app, without going back and forth. Here's the JSON schema you can use for the Post deployment webhook:  

{
  "properties": {
    "author": {
      "type": "string"
    },
    "authorEmail": {
      "type": "string"
    },
    "complete": {
      "type": "boolean"
    },
    "deployer": {
      "type": "string"
    },
    "endTime": {
      "type": "string"
    },
    "hostName": {
      "type": "string"
    },
    "id": {
      "type": "string"
    },
    "lastSuccessEndTime": {
      "type": "string"
    },
    "message": {
      "type": "string"
    },
    "progress": {
      "type": "string"
    },
    "receivedTime": {
      "type": "string"
    },
    "siteName": {
      "type": "string"
    },
    "startTime": {
      "type": "string"
    },
    "status": {
      "type": "string"
    },
    "statusText": {
      "type": "string"
    }
  },
  "type": "object"
}

 

Once configured, you can select all the properties as defined in the schema and make it all look less "JSON-ish". You can even throw some HTML in there. With Logic Apps the sky (or cloud) is the limit :)

 

This takes some tweaking and some trial and error to get it to look acceptable. But you can use the Logic App to re-submit a previous run (just browse to the run history), perform a deployment through deployment center or just commit new code to your repository. When configuring the Logic App, I just like to use the option to re-submit a previous run because it's fast. What I ended up with is something similar to this:

After some trial and error and digital cosmetics, the E-Mail looks acceptable to send people other than myself.

 

Now you have the possibility to receive E-Mails when someone or something has deployed a new version. With just using regular deployments through Kudu and without using the options that Azure DevOps generally provides (still, you should really use Azure Pipelines!) :)

And even tho Kudu you can post a Webhook to almost anything as long as it's got an HTTP trigger, you can also choose to expand your Logic App. For instance, to post to Microsoft Teams: