Build & deploy to Java web app

Azure DevOps Services

A web app is a lightweight way to host a web application. In this step-by-step guide, learn how to create a pipeline that continuously builds and deploys a Java app. Each commit can automatically build at GitHub and deploy to an Azure App Service. You can use whatever runtime you prefer, Tomcat, or Java SE.

For more information, see Java for Azure App Service.

Tip

If you only want to build a Java app, see Build Java apps.

Prerequisites

Make sure you have the following items:

  • A GitHub account where you can create a repository. Create one for free.

  • An Azure DevOps organization. Create one for free. If your team already has one, then make sure you're an administrator of the Azure DevOps project that you want to use.

  • An ability to run pipelines on Microsoft-hosted agents. You can either purchase a parallel job or you can request a free tier.

  • An Azure account. If you don't have one, you can create one for free.

    Tip

    If you're new at this, the easiest way to get started is to use the same email address as the owner of both the Azure Pipelines organization and the Azure subscription.

Get the code

Select the runtime you want to use.

If you already have an app in GitHub that you want to deploy, you can create a pipeline for that code.

If you are a new user, fork this repo in GitHub:

https://github.com/spring-petclinic/spring-framework-petclinic

Create an Azure App Service

Sign in to the Azure Portal, and then select the Cloud Shell button in the upper-right corner.

Create an Azure App Service on Linux.

# Create a resource group
az group create --location eastus2 --name myapp-rg

# Create an app service plan of type Linux
az appservice plan create -g myapp-rg -n myapp-service-plan --is-linux

# Create an App Service from the plan with Tomcat and JRE 8 as the runtime
az webapp create -g myapp-rg -p myapp-service-plan -n my-app-name --runtime "TOMCAT|8.5-jre8"

Create the pipeline

  1. Sign-in to your Azure DevOps organization and go to your project.

  2. Go to Pipelines, and then select New pipeline.

  3. Do the steps of the wizard by first selecting GitHub as the location of your source code.

  4. You might be redirected to GitHub to sign in. If so, enter your GitHub credentials.

  5. When you see the list of repositories, select your repository.

  6. You might be redirected to GitHub to install the Azure Pipelines app. If so, select Approve & install.

  1. When the Configure tab appears, select Show more, and then select Maven package Java project Web App to Linux on Azure.

  2. You can automatically create an Azure Resource Manager service connection when you create your pipeline. To get started, select your Azure subscription where you created a resource group.

  3. Select Validate and configure. The new pipeline includes a new Azure Resource Manager service connection.

    As Azure Pipelines creates an azure-pipelines.yml file, which defines your CI/CD pipeline, it:

    • Includes a Build stage, which builds your project, and a Deploy stage, which deploys it to Azure as a Linux web app.
    • As part of the Deploy stage, it also creates an Environment with default name same as the Web App. You can choose to modify the environment name.
  4. Make sure that all the default inputs are appropriate for your code.

  5. Select Save and run, after which you're prompted for a commit message because the azure-pipelines.yml file gets added to your repository. After editing the message, select Save and run again to see your pipeline in action.

See the pipeline run, and your app deployed

As your pipeline runs, your build and deployment stages go from blue (running) to green (completed). To watch your pipeline in action, you can select stages and jobs.

After the pipeline runs, check out your site!

https://my-app-name.azurewebsites.net/petclinic

Also explore deployment history for the app by going to the "environment". From the pipeline summary:

  1. Select the Environments tab.
  2. Select View environment.

Clean up resources

Whenever you're done with the resources you created, you can use the following command to delete them:

az group delete --name myapp-rg

Enter y when you're prompted.

Next steps