This tutorial shows you how to deploy a Java app to Azure Web App for Tomcat using Azure App Service Plugin. Below are the major steps in this tutorial.
- Create Azure Web App
- Prepare Jenkins server
- Create job
- Build and Deploy Java Application to Azure Web App
- Clean Up Resources
Create an Azure Web App with built-in support for Tomcat by Azure portal or Azure CLI.
-
Deploy a Jenkins Master on Azure
-
Install the plugins in Jenkins. Click 'Manage Jenkins' -> 'Manage Plugins' -> 'Available', then search and install the following plugins: Azure App Service Plugin, EnvInject Plugin.
-
Add a Credential in type "Microsoft Azure Service Principal" with your service principal.
-
Add a new job in type "Pipeline".
-
Enable "Prepare an environment for the run", and put the following environment variables in "Properties Content":
AZURE_CRED_ID=[your credential id of service principal] RES_GROUP=[your resource group of the web app] WEB_APP=[the name of the web app] DOCUMENTDB_URI=[the URI of the DocumentDB] DOCUMENTDB_KEY=[the key of the DocumentDB] DOCUMENTDB_DBNAME=[the name of the DocumentDB]
You can save your DocumentDB settings in your Web App Application settings if you would like to manage your application settings independently.
-
This application's default package type is jar. So you have to make some changes to enable it create a deployable war file. Please refer to Spring Boot doc here.
-
Choose "Pipeline script from SCM" in "Pipeline" -> "Definition".
-
Fill in the SCM repo url and script path. (Script Example)
-
Verify you can run your project successfully in your local environment. (Run project on local machine)
-
Run jenkins job.
-
Navigate to the website from your favorite browser. You will see this app successfully running on Azure Web App.
Delete the Azure resources you just created by running below command:
az group delete -y --no-wait -n <your-resource-group-name>