Java CI/CD using Jenkins and Azure Web Apps
Azure App Service is a fast and simple way to create web apps using Java, Node, PHP or ASP.NET, as well as support for custom language runtimes using Docker. A continuous integration and continuous deployment (CI/CD) pipeline that pushes each of your changes automatically to Azure app services allows you to deliver value faster to your customers.
Deployment steps
Create service principal with the
Contributor
role with Azure CLI if you don't have one in your subscription.az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}"
Your appId, password, sp_name, and tenant are returned. Make a note of the appId and password.
Click the Deploy to Azure button at the beginning of this document, and fill in the settings.
- Jenkins VM Admin Username - Provide the user name for the Jenkins Virtual Machine.
- Jenkins VM Admin Password - Provide the password for the Jenkins Virtual Machine, it must meet the complexity requirements, e.g.
30Jan2@18
- Jenkins Dns Prefix - Provide the unique DNS name for the Public IP used to access the Jenkins Virtual Machine.
- Jenkins Release Type - Provide the Jenkins release type.
- Repository Url - Provide the GitHub repository URL for the source code.
- Client Id - Provide the client id for Azure service principal, use appId noted above.
- Client Secret - Provide the client secret for Azure service principal, use password noted above.
- App Dns Prefix - Provide the prefix name for web app components, accepts numbers and letters only.
- My Sql Admin Login - Provide the user name for MySQL admin login.
- My Sql Admin Password - Provide the password for MySQL admin login, it must meet the complexity requirements, e.g.
30Jan2@18
- _artifacts Location - Leave it with the default value.
- _artifacts Location Sas Token - Leave it with the default value.
Usage
Check Jenkins Build Job Status
Find out the Jenkins URL in either Outputs section of the ARM template deployment blade, or in the
JenkinsPublicIP
component in the new resource group.Open Jenkins URL in browser.
The
BuildWebApp
job will be queued automatically once the deployment complete, it will take several minutes to create and run the new build agent on Azure.You could also check the build agent status in the same resource group as Jenkins.
Jenkins build will start once the build agent is running and available.
Click the build number (e.g.
#1
).Click the Console Output in the left sidebar.
The build console output will be shown and keep refreshed until the build completes, you will also notice that a copy of the build is uploaded to the blob storage.
Manage Jenkins
If you want to manage Jenkins, e.g. trigger a build manually, just follow the steps below.
Click the log in button on the top right of the Jenkins page.
The Jenkins console is inaccessible through unsecured HTTP so instructions are provided on the page to access the Jenkins console securely from your computer using an SSH tunnel.
Set up the tunnel using the
ssh
command on the page from the command line, replacingusername
with the name of the virtual machine admin user chosen earlier.ssh -L 127.0.0.1:8080:localhost:8080 username@mswatest001.eastus.cloudapp.azure.com
Or use PuTTY for Windows client alternatively.
putty -ssh -L 127.0.0.1:8080:localhost:8080 username@mswatest001.eastus.cloudapp.azure.com
Get the initial password by running the following command in the command line while connected through SSH to the Jenkins VM.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Navigate to http://localhost:8080/ on your local machine.
Sign in with the user name
admin
and the initial password above.Proceed management operations as need.
Connect to Java Web App
The Java web app URL could be found in either the Outputs section of the ARM template deployment blade, or in the App Service component.
Navigate to the web app, it will query MySQL database and return the data.
Tags: Microsoft.Storage/storageAccounts, Microsoft.Web/serverfarms, Microsoft.Web/sites, config, MySql, microsoft.insights/components, Microsoft.DBforMySQL/servers, firewallrules, databases, Microsoft.Resources/deployments, Microsoft.Network/publicIPAddresses, Microsoft.Network/networkSecurityGroups, Microsoft.Network/virtualNetworks, Microsoft.Network/networkInterfaces, Microsoft.Compute/virtualMachines, extensions, CustomScript