This tutorial shows you how to deploy a Java SE app to Azure Web App 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 SE Application to Azure Web App
- Clean Up Resources
Create an Azure Web App with Java as a rumtime stack by Azure portal or Azure CLI
If you use Web App on Linux with jre runtime stack, you have to build your app with port 80 or set the web app setting with
PORT=8080
-
Deploy a Jenkins Master on Azure
-
Install maven and zip commands for your Jenkins Master.
-
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.
-
Copy jenkins/web.config to
src/main/resources/web.config
and replace the${JAR_FILE_NAME}
with your app's jar file name. -
Choose "Pipeline script from SCM" in "Pipeline" -> "Definition".
-
Fill in the SCM repo url and script path. (Script Example)
-
Archive your jar file and web.config in zip format manually or in command like the example script above.
-
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>