In this lab, we will use Jenkins to create a build using maven to use it in our HOL-OSS-DEVOPS project.
This lab aims to get you familiar with Jenkins on Azure Cloud.
You must have the Azure account mentioned in Lab 01.
-
Browse to the Azure Portal: https://portal.azure.com/
You can use any of the Jenkins templates showed below; for this lab we will use Jenkis template published by Docker. This will setp up an Ubuntu VM with the Docker engine installed and a Jenkins container running on it.
-
Fill in the basic machine settings:
Name: OSSDevOpsHOL
VM Disk Type: HDD
Username: ossdevopshol-user
Authentication type: Password
Password: Choose a password you will remember
Subscription: Your Azure subscription
Resource group: (Create new) OSSDevOpsHOL
Location: Your preferred location -
Select the "A0 Basic" virtual machine size. If you are unable to see this machine size, make sure you are viewing "All" machine sizes and not only those that are "Recommended" (you can toggle this view in the upper right corner of the machine size viewer).
-
In the third step you can select optional extensions to be installed, but we will simply leave this as-is and select OK to move to the next step.
-
Validate the configuration settings you've selected and click OK.
-
When the VM has been deployed, select the machine to open the overview window as shown below.
-
Take note of the "Public IP address" of your machine, you will need this in the next step to access jenkins
-
Go to http://{your-public-ip}:8080 to access Jenkins
-
When you log in to Jenkins for the first time, it will ask you to unlock it. To unlock, we will connect directly to the machine that Jenkins in installed on and retrieve the password.
-
If you don't have PuTTY already, download the PuTTY client here.
-
Run the PuTTY.exe file to start the client.
-
Enter the public IP address from step 2 into the "Host name (or IP address) textbox" and click "Open" to connect to the machine.
-
When asked, type in the username and password you specified when you created the virtual machine in section 2.2 of this lab.
-
In order to access the Administrators password used to unlock Jenkins, we need to access the Docker container in which Jenkins is installed. List all containers by running the following command:
docker ps
-
Now that we have the container ID of the Jenkins container, we can access its logs by running the following command:
docker logs {containerID}
-
You will now see the Administrators password required to unlock Jenkins:
-
Provide the Administratior password and continue to the next step.
-
Select "Install suggested plugins" and wait for the installation to complete.
-
Create a new admin user in Jenkins by filling out the following fields and clicking "Save and Finish"
-
Once you have created a new user, Jenkins is ready! Click "Start using Jenkins" to proceed.
-
To create our build we will need install the maven plugins. Browse to Manage Jenkins-> Manage Plugins
-
Select the "Available" tab to view all available plugins and mark the "Maven Integration Plugin" for download. Click "Install without restart" to install the plugin.
-
Scroll down to the "Maven" section and click on the "Add Maven" button.
-
Specify the name "maven" and ensure that the "Install automatically" checkbox is marked.
-
Click "Save".
-
After configuring the Maven installation you need to configure the Maven Option Variables. Click on "Configure System".
-
Scroll down to the "Maven Project Configuration" section and click the arrow to the right of the textbox to expand to multiple lines.
-
Specify the following values for "Global MAVEN_OPTS":
-Xmx512m -XX:MaxPermSize=128m -Pupstream
-
Click "Save".
-
Create a "Freestyle project" with the name "MavenBuid" and click "OK" to continue.
-
Click on the "Build" tab of the configuration. In the "Add build step" dropdown, select "Invoke top-level Maven targets".
-
Click on the arrow next to the "Goals" textbox to expand the textbox to multiple lines.
-
Select the "Maven Version" we set up previously and specify the following goals for the build and click on the "Advanced..." button:
clean package
-
Add the following "POM" file path to the configuration:
sample-app/pom.xml
-
Click on the "Post-build Actions" tab and add a post-build action of type "Archive the artifact" where you archive the files matching the following pattern:
**/target/*.war
-
Click on "Save".