You are on page 1of 6

Jenkins

Introduction –
Exercise Book

TRAINING MATERIALS – Jenkins Exercise Book

Contacts
Devdatta.Gonsai@qa.com
team.qac.all.trainers@qa.com
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:

sudo apt-get update

sudo apt-get install -y default-jdk

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:

sudo apt-get install maven

sudo apt-get install git

mvn -version

git –version

Installing Jenkins

Next, we can start the actual install of Jenkins. The process we need to take is as follows:

a. Get a key to allow us to download Jenkins


b. Update our sources list directory with a new file for the Jenkins download
c. Update our package library
d. Install Jenkins through the apt package manager

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:

sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ >


/etc/apt/sources.list.d/jenkins.list'

5. Finally, let’s update our package manager cache one more time and install Jenkins
through apt:

sudo apt-get update

sudo apt-get install -y jenkins

1. Consulting – Lab Manual


QA 3
Accessing Jenkins

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. Consulting – Lab Manual


QA 4
Exercise 2 – Building with Jenkins
Creating and Pushing Code

1. First create a very basic java application, that Jenkins will execute – for example, a
HelloWorld application. For example:

2. In a file named “HelloWorld.java”


3. Save this onto a new branch of your Bitbucket Repository called ‘java’, and push it up:
$ git checkout -b java
commit -m
“Basic
java app”
$ git push
origin

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

1. Consulting – Lab Manual


QA 5
Run the Build

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.

1. Consulting – Lab Manual


QA 6

You might also like