Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Latest commit

 

History

History
69 lines (44 loc) · 3.04 KB

deploy-to-azure-web-app-javase-using-jenkins.md

File metadata and controls

69 lines (44 loc) · 3.04 KB

Deploy to Azure Web App for Java SE applictions using Jenkins

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

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

Prepare Jenkins server

  1. Deploy a Jenkins Master on Azure

  2. Install maven and zip commands for your Jenkins Master.

  3. Install the plugins in Jenkins. Click 'Manage Jenkins' -> 'Manage Plugins' -> 'Available', then search and install the following plugins: Azure App Service Plugin, EnvInject Plugin.

  4. Add a Credential in type "Microsoft Azure Service Principal" with your service principal.

Create job

  1. Add a new job in type "Pipeline".

  2. 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.

  3. Copy jenkins/web.config to src/main/resources/web.config and replace the ${JAR_FILE_NAME} with your app's jar file name.

  4. Choose "Pipeline script from SCM" in "Pipeline" -> "Definition".

  5. Fill in the SCM repo url and script path. (Script Example)

  6. Archive your jar file and web.config in zip format manually or in command like the example script above.

Build and Deploy Java SE application to Azure Web App

  1. Verify you can run your project successfully in your local environment. (Run project on local machine)

  2. Run jenkins job.

  3. Navigate to the website from your favorite browser. You will see this app successfully running on Azure Web App.

Clean Up Resources

Delete the Azure resources you just created by running below command:

az group delete -y --no-wait -n <your-resource-group-name>