Jenkins Foundations Exercises
Jenkins Foundations Exercises
Introduction –
Exercise Book
Contacts
[email protected]
[email protected]
1. Consulting – Lab Manual
QA 2
Exercise 1 – Installing Jenkins
Pre-requisites
1. Jenkins requires Java as a dependency to run, so we will need to install the JDK before
we can complete the install. We can run the below commands to do this:
java -version
javac -version
2. To complete the set up of our environment, we are also going to install Maven and Git,
for building and repository sourcing purposes. We can run the following commands
below to do this:
mvn -version
git –version
Installing Jenkins
Next, we can start the actual install of Jenkins. The process we need to take is as follows:
3. Firstly, let’s get the key for Jenkins with the use of wget:
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key |
sudo apt-key add –
4. Then, let’s update our sources list directory with a new file – Jenkins.List – and echo
the location of where to download Jenkins into this file:
5. Finally, let’s update our package manager cache one more time and install Jenkins
through apt:
We will now be able to access Jenkins on the web browser of our virtual machine at
localhost:8080.
6. Follow the instructions to find the initial admin password. Accessing the listed file in the
directory specified will give you the password you need. You may need to become the
root user with the below command if you are denied permission:
sudo su
7. Choose the ‘install the suggested plugins’ option given to you. This will install several
plugins needed for Jenkins to function.
8. Continue as an admin user rather than making a new user. If you ever close your
Jenkins UI, the username will be admin, with the password being the initial admin pass
given for setup.
Jenkins is installed!
1. First create a very basic java application, that Jenkins will execute – for example, a
HelloWorld application. For example:
java
Making the Job in Jenkins
4. On the Jenkins dashboard, click on “New Item” from the left-hand sidebar or “create
new jobs” which will appear if there are no other jobs configured for your server.
5. On the next screen enter the item name as “HelloWorld” and set the type of job to be
created as a “Freestyle project”
6. d. Toggle on the ‘GitHub project’ option and enter the URL for your Project (the URL
used to git clone the repository).
7. Under ‘Source Code Management’, select the option for Git and add the Repository
URL (http) and supply Jenkins with your credentials (the username and password used
to push and pull from Bitbucket).
8. For ‘Branches to build’ specify the new branch where the java app is located - “*/java”
9. Add a Build Step under the Build Environment of type ‘Execute shell’ with the following
commands:
javac HelloWorld.java
java HelloWorld
10. To tell Jenkins where to compile the application from and run it. Save the job and
execute it with “Build Now”
11. On the Build for the HelloWorld project, select ‘Console Output’ to see the steps
Jenkins runs through. The output should conclude with the below:
+ javac HelloWorld.java
+ java HelloWorld
Hello, World
Finished: SUCCESS
a.