Deploy to Azure Functions with DevOps Starter

Azure DevOps Starter presents a simplified experience where you can bring your existing code and Git repo or choose a sample application to create a continuous integration (CI) and continuous delivery (CD) pipeline to Azure.

DevOps Starter also:

  • Automatically creates Azure resources, such as Azure Functions

  • Creates and configures a release pipeline in Azure DevOps for CI/CD

In this tutorial, you will:

  • Use DevOps Starter to deploy an ASP.NET app to Azure Function
  • Configure Azure DevOps and an Azure subscription
  • Examine the Azure Function
  • Examine the CI pipeline
  • Examine the CD pipeline
  • Commit changes to Git and automatically deploy them to Azure
  • Clean up resources

Currently the supported runtimes for functions are .NET and Node.js. We use. NET runtime for this tutorial to deploy to Azure Functions.

Prerequisites

Use DevOps Starter to deploy an ASP.NET app to Azure Functions

DevOps Starter creates a CI/CD pipeline in Azure Pipelines. You can create a new Azure DevOps organization or use an existing organization. DevOps Projects also creates Azure resources, such as an IoTHub, in the Azure subscription of your choice.

  1. Sign in to the Azure portal

  2. In the search box, type DevOps Starter, and then select. Click on Add to create a new one.

    The DevOps Starter dashboard

  3. Select .NET, and then select Next. Under Choose an application framework, select ASP.NET and click Next.

  4. Select Function App and then select Next.

Configure Azure DevOps and Azure subscription

  1. Enter a name for your Azure DevOps project.

  2. Create a new Azure DevOps organization, or select an existing organization.

  3. Select your Azure subscription.

  4. To view additional Azure configuration settings and to identify the pricing tier and location, click on Additional settings. This pane displays various options for configuring the pricing tier and location of Azure services.

  5. Exit the Azure configuration area, and then select Done.

  6. After few minutes, the process is completed. A sample ASP.NET app is set up in a Git repo in your Azure DevOps organization, a Function App, and Application Insights is created, a CI/CD pipeline is executed, and your app is deployed to Azure.

    After all this is completed, the Azure DevOps Starter dashboard is displayed in the Azure portal. You can also go to the DevOps Starter dashboard directly from All resources in the Azure portal.

    This dashboard provides visibility into your Azure DevOps code repository, your CI/CD pipeline, and your Azure Function. You can configure additional CI/CD options in your Azure DevOps pipeline. At the right, select Function App to view.

Examine the Function App

DevOps Starter automatically configures function app, which you can explore and customize. To get to know the function app, do the following:

  1. Go to the DevOps Starter dashboard.

    DevOps Projects Dashboard

  2. At the right, select the function app. A pane opens for the function app. From this view you can perform various actions such as operations monitoring, searching logs.

    Function App

Examine the CI pipeline

DevOps Starter automatically configures a CI/CD pipeline in your Azure DevOps organization. You can explore and customize the pipeline. To familiarize yourself with it, do the following:

  1. Go to the DevOps Starter dashboard.

  2. Click on the hyperlink under Build. A browser tab displays the build pipeline for your new project.

    Screenshot shows the Azure portal DevOps Starter dashboard with an arrow pointing to a link under Build in the C I / C D pipeline.

  3. Select Edit. In this pane, you can examine the various tasks for your build pipeline. The build performs various tasks, such as fetching source code from the Git repo, building the application, running unit tests, and publishing outputs that are used for deployments.

  4. Select Triggers. DevOps Starter automatically creates a CI trigger, and every commit to the repo starts a new build. Optionally, you can choose to include or exclude branches from the CI process.

  5. Select Retention. Depending on your scenario, you can specify policies to keep or remove a certain number of builds.

  6. At the top of the build pipeline, select the build pipeline name.

  7. Change the name of your build pipeline to something more descriptive, and then select Save from the Save & queue dropdown.

  8. Under your build pipeline name, select History. This pane displays an audit trail of your recent changes for the build. Azure DevOps keep track of any changes made to the build pipeline, and it allows you to compare versions.

Examine the CD release pipeline

DevOps Starter automatically creates and configures the necessary steps to deploy from your Azure DevOps organization to your Azure subscription. These steps include configuring an Azure service connection to authenticate Azure DevOps to your Azure subscription. The automation also creates a release pipeline, which provides the CD to Azure. To learn more about the release pipeline, do the following:

  1. Navigate to the Pipelines | Releases.

  2. Click on Edit.

  3. Under Artifacts, select Drop. The build pipeline you examined in the previous steps produces the output that's used for the artifact.

  4. At the right of the Drop icon, select Continuous deployment trigger. This release pipeline has an enabled CD trigger, which executes a deployment every time a new build artifact is available. Optionally, you can disable the trigger so that your deployments require manual execution.

  5. At the right, select View releases to display a history of releases.

  6. Click on the release, which will display the pipeline. Click on any environment to check the release Summary, Commits, associated Work Items.

  7. Select Commits. This view shows code commits that are associated with this deployment. Compare releases to view the commit differences between deployments.

  8. Select View Logs. The logs contain useful information about the deployment process. You can view them both during and after deployments.

Commit code changes and execute CI/CD

Note

The following procedure tests the CI/CD pipeline by making a simple text change.

You're now ready to collaborate with a team on your app by using a CI/CD process that automatically deploys your latest work to your Azure Function. Each change to the Git repo starts a build in Azure DevOps, and a CD pipeline executes a deployment to Azure. Follow the procedure in this section, or use another technique to commit changes to your repo. For example, you can clone the Git repo in your favorite tool or IDE, and then push changes to this repo.

  1. In the Azure DevOps menu, select Repos | Files, and then go to your repo.

  2. The repository already contains code called SampleFunctionApp based on the application language that you chose in the creation process. Open the Application/SampleFunctionApp/Function1.cs file.

  3. Select Edit, and then make a change to line number 31 . For example, you can update it to Hello there! Welcome to Azure Functions using DevOps Starter

  4. At the top right, select Commit, and then select Commit again to push your change.

  5. Open the Application/SampleFunctionApp.Test/Function1TestRunner.cs file.

  6. Select Edit, and then make a change to line number 21. For example, you can update it to Hello there! Welcome to Azure Functions using Azure DevOps Starter.

    After a few moments, a build starts in Azure DevOps and a release executes to deploy the changes. Monitor the build status on the DevOps Starter dashboard or in the browser with your Azure DevOps organization.

Clean up resources

You can delete the related resources that you created when you don't need them anymore. Use the Delete functionality on the DevOps Starter dashboard.

Next steps

You can optionally modify these build and release pipelines to meet the needs of your team. You can also use this CI/CD pattern as a template for your other pipelines. In this tutorial, you learned how to:

  • Use DevOps Starter to deploy an ASP.NET Core app to Azure Function
  • Configure Azure DevOps and an Azure subscription
  • Examine the Azure Function
  • Examine the CI pipeline
  • Examine the CD pipeline
  • Commit changes to Git and automatically deploy them to Azure
  • Clean up resources