| title | Build and deploy to a Java web app on Linux |
|---|---|
| description | Continuous integration and deployment (CI/CD) to a Java web app on Linux. |
| ms.topic | tutorial |
| ms.custom | devx-track-extended-java, linux-related-content |
| ms.assetid | 49253EA0-9CD6-4082-A303-95F78C7599C2 |
| ms.date | 12/22/2021 |
| monikerRange | azure-devops |
[!INCLUDE version-eq-azure-devops]
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.
[!INCLUDE include] [!INCLUDE include]
Select the runtime you want to use.
[!INCLUDE include]
https://github.com/spring-petclinic/spring-framework-petclinic
[!INCLUDE include]
https://github.com/spring-projects/spring-petclinic
[!INCLUDE include]
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 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 Java SE as the runtime
az webapp create -g myapp-rg -p myapp-service-plan -n my-app-name --runtime "JAVA|8-jre8"
[!INCLUDE include]
-
When the Configure tab appears, select Show more, and then select Maven package Java project Web App to Linux on Azure.
-
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.
-
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.
-
Make sure that all the default inputs are appropriate for your code.
-
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.
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
After the pipeline runs, check out your site!
https://my-app-name.azurewebsites.net
Also explore deployment history for the app by going to the "environment". From the pipeline summary:
- Select the Environments tab.
- Select View environment.
[!INCLUDE include]