Extending KUDU

In part 1 of the article we understand the various features of the KUDU and the way it helps the developer as part of Continuous Deployment. In this article we will see how to extend KUDU and deeper dive into WebHooks.

Following are the various ways to Extend

Custom Deployment Script:

Open DebugConsole under {website}.scm.azurewebsites.net and you can see the below two files.

.Deployment

It just contains the command file which needs to be executed. We can customize this file based on our requirement.

[config]

command = deploy.cmd

 Deploy.cmd

It contains n number of steps to be executed as part of deployment process. For example

  • Install the necessary modules/packages to run the web application.
  • Build the .csproj and see whether there are any build issues or not
  • Using KuduSync synchronize the files

In the above case I only verified like whether the web application is building successfully or not, if it builds then push the changes to azure website.  Requirement is like only publish the change to azure website when the testing project is built successfully and all the unit test cases are passed.

How this can be accomplished?

  • Download NUnit.exe and related dlls
  • Modify the Deploy.cmd
    • Write the script for building the test project
    • Invoke NUnit.exe to run all the test cases by pointing to the test project dll
  • If both are successful then only push the changes to Azure web site using KUDUSync.

 Post Deployment Action:

There are no hard and fast rules like your entire logic needs to come under Deploy.cmd. Suppose you want to perform some action on post deployment create a cmd file and specify it here which will be invoke automatically. Corresponding section is shown here.

KuduPart_2

WebHooks:

A Webhook is a HTTP Callback. A web application implementing webhooks POST a message to a URL when certain things happen. We can use WebHooks for Azure Alerts as well.

Scenarios:

When an external system wants to know when some event of interest happens. The system register a callback url which will be called each time when the action has taken place. Examples

  • Notify a user when a metric crosses a threshold.
  • Send an email when deployment is done.
  • Tweet when deployment has succeeded.
  • Call/SMS when deployment has failed.

There are couple of ways to implement Webhooks.

  • We can write our own service and configure under the Webhooks UrlKuduPart_2.1
  • We can sign in with third party services like zapier and use the various triggers provided by them. Right now we have 2 supported triggers
    • New Triggered WebJob Run: Triggers when a job completes a run.
    • New WebApp Deployment: Triggers when a git deployment to azure website completes.

More information is available at: https://zapier.com/help/windows-azure-web-sites/

  • Integrate with PagerDuty (Incident Resolution Platform). Webhooks allow you to do more with Azure Alerts.

Site Extensions:

KUDU comes with great tools like debug console, process explorer and the ability to configure web hooks etc. Site Extensions allows us add more additional tools into KUDU environment. There are some tools available under gallery

KuduPart_2.2

For example if you want to use File Counter Extension which will give you total number of files in your web application.  Creating custom Site Extension is out of scope of this article, I will explain this in detail in my next article.

Conclusion

In this way we can extend the functionality of the KUDU by writing custom deployment scripts, providing custom hooks by subscribing to various incident management systems and provide additional tools using Site Extensions.