Tutorial: CI/CD using Apache Subversion, Jenkins in Azure and Tomcat
WRITTEN BY
/en-us/opensource/blog/author/xiang-yan
In this blogpost, we will show you how to provision a Jenkins VM and setup a CI/CD pipeline to connect a code repository in Apache Subversion (SVN) and deploy the application into a Tomcat service.
We start from the solution template in Azure Marketplace, since that’s the fastest and easiest path to get Jenkins up and running in Azure. You can follow the steps using your existing Jenkins server, regardless of whether it’s run on premise or in the cloud. Azure offers Azure Web App with Tomcat on Linux. It is in public preview with build-in support for Tomcat and OpenJDK. It is fully managed by Microsoft and easy to scale. We will demo how to deploy the generated war package into Azure Web App for Java. And of course if you have your own Tomcat server, we will cover this as well.
This is the flow implemented in this post:
- Developers commit code change into Subversion
- Jenkins builds and packages application into war package
- Jenkins deploys the war package into Tomcat service
Deploy Jenkins server
In the Azure portal, select Create a resource and search for Jenkins. Select the Jenkins offering with a publisher of Microsoft and select Create.
Enter the following information on the basics form and click OK when done.
- Name – name for the Jenkins deployment.
- User name – this user name is used as the admin user for the Jenkins virtual machine.
- Authentication type – SSH public key is recommended. If selected, copy in an SSH public key to be used when logging into the Jenkins virtual machine.
- Subscription – select an Azure subscription.
- Resource group – create a new or select an existing resource group.
- Location – select a location for the Jenkins server.
On the additional settings form, complete the following items:
- Size – Select the appropriate sizing option for your Jenkins virtual machine.
- VM disk type – Specify either HDD (hard-disk drive) or SSD (solid-state drive) for the Jenkins server.
- Virtual network – (Optional) Select Virtual network to modify the default settings.
- Subnets – Select Subnets, verify the information, and select OK.
- Public IP address – Selecting the Public IP address allows you to give it a custom name, configure SKU, and assignment method.
- Domain name label – Specify a value to create a fully qualified URL to the Jenkins virtual machine.
- Jenkins release type – Select the desired release type from the options: LTS, Weekly build, or Azure Verified.
Configure Jenkins
In the Azure portal, browse to the Jenkins Resource Group, select the Jenkins virtual machine, and take note of the DNS name.
Open up a terminal session on your development system, and paste in the SSH string from the last step. Update ‘username’ to the username specified when deploying the Jenkins server.
Once connected, run the following command to retrieve the initial admin password.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Select Manage Jenkins then Manage Plugins. In Available tab, search Maven Integration and Deploy to container and install them.
Create build job
Now create a Jenkins build job. Select New Item, give the build project a name such as svn-tomcat-demo, select Maven project, and click OK.
Please download the sample code and check the code into your SVN server.
Under Build, input package for Goals and options.
- Deploy to Azure Web App
Microsoft has a Jenkins plugin to deploy to Azure Web App service.
Under Post-build Actions, select add post-build action and select Publish an Azure Web App. Add your Azure service principal and from the drop-down list, you can choose your Web App Service.
- Deploy to Tomcat server on VM
If you have your own Tomcat server, you can deploy your package to your server as well.
Under Post-build Actions, select add post-build action and select Deploy war/ear to a container. Input Tomcat URL and credential.
Run the build job
To test the build job, manually start a build.
Select Build Now to start a build job. It takes a few seconds for the job to start, when running, you should see status similar to the following images.
Here you go!