Serverless computing has become a hot topic these days. It is providing you with paying only for the actual time your code is running and resources you are consuming without any worries about infrastructure. Azure functions let you build functions that can scale dynamically based on the needs, with a languages of your choice. When you install Visual Studio Azure Development workload you get templates for developing Azure Functions. Let’s look at how to create a simple Azure Function “Hello World” in Visual Studio and most importantly how to get your CI/CD pipeline ready within couple of minutes.
Install continuous delivery extension for Visual Studio 2017 from Visual Studio Marketplace.
In the dialog provide your Microsoft account details and you would be able to see the team project Git repository. Select the branch that you have committed your Azure Function code. Select you Azure Subscription and click Edit button to provide additional information for Azure Function app.
The Advantage of generating the build and deployment pipeline will help you get started quickly. Let’s inspect tasks setup in these definitions to understand how the steps are performed so that it enables you to do necessary enhancements to support you real production scenarios such as adding additional environments, say QA, Staging or Prod, and adding further configurations etc.
NuGet Restore task will restore any NuGet packages used and Visual Studio build step will build and publish the app with the arguments passed to MSBuild. The build will package the Function app as a MSDeploy package. You may want to introduce package as NuGet package and push it to a package management feed as an enhancement. We can explore these options in a later post.
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
Visual Studio Test task will run any unit tests and publish symbols will enable debugging by making .pdbs available. More information on publishing symbols for debugging can be found here. Executed build will create a MSDeploy package as shown below.
Azure App Service deployment task is configured supporting deployment of the Function App as shown below. The App Type is set to Function App and package from the build is used for deployment. The task allows you to use variable substitution etc. as further enhancements.
The Service Endpoint created to connect with the Azure subscription is scoped to the resource group picked in the Visual Studio. You can inspect the service endpoint by clicking the Manage link next to the Azure Subscription and the opening the new service endpoint for update.
You can verify the current connection and change scope or even define new service endpoints to target different Azure subscriptions depending on you target environment needs. For example you production environment can be totally different Azure subscription. Then you can clone the release pipeline auto generated environment to create the next step in the pipeline.
Beauty of the Continuous Delivery extension to Visual Studio is it creates you entire CI/CD pipeline for Azure Function apps and even executes the first release to get it deployed to the first target environment. This enables you to get started really quick and do further enhancement as and when needed.