Installing Jenkins on Ubuntu

 

Java

 

Jenkins is created in Java and so requires JRE to be installed on the system to run. At the time of writing this, Jenkins supports Java 8. So check if Java is installed or not and install Java if it is not already installed on the system. You can follow these steps if you are not sure  about installing java on your Ubuntu machine.

 

Jenkins Installation

 

Run the below command to  download the package key from Jenkins repository and install it on the machine.

 

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
 
It should download and install Jenkins package key, but some times you may see failures similar to the below.

 

13

 

In case of these failures, run the same command in 2 different steps. Run the below 2 commands to download and install the jenkins key.

sudo wget –v –o https://pkg.jenkins.io/debian-stable/jenkins.io.key

 

sudo apt-key add jenkins.io.key

 

14

 

15

 

The distributions for Debian and Ubutunu are same, so don’t get confused with Debian term in the urls.

Once the jenkins key is successfully added to the machine, we will add jenkins distribution url to the ubuntu repository source list.

The sources list is configured in the /etc/apt/ folder, so navigate to that folder using the below command.

 

cd /etc/apt/

 

16

 

Run the below command to open the sources.list file and edit it.

sudo nano sources.list

18

 

Add the below line to the file and then save the file.

deb https://pkg.jenkins.io/debian-stable binary/

 

19

 

Since we added a new repository to the sources list, let us run an update to apply the changes we made.

 

sudo apt-get update

 

21

 

Once the package list is updated, let us start installing jenkins.

 

sudo apt-get install jenkins

22

As indicated in the above screen shot, it may fail due to missing dependency ‘Depends’.

 

The ‘Depends’ is available in universe repository, so install it before trying to reinstall Jenkins again.

 

sudo add-apt-repository universe

 

24

 

Once universe is installed successfully, try reinstalling jenkins again.

 

sudo apt-get install jenkins

 

25

 

Type ‘y’ when the installer asks whether you want to continue with the installation.

 

26

27

 

Jenkins is successfully installed on a Ubuntu machine.

 

Configuration

The jenkins configuration file is /etc/default/jenkins which contains lot of configurations related to jenkins instance.

Run the below command to review the jenkins configuration file.

cd /etc/default/

 

28

sudo nano jenkins

32

 

The configuration file contains information on the location of jenkins app, whether it is to run as a stand alone app or it is going to run in a web container, the location of jenkins war and port on which the app runs etc. We will review these configurations later.

29

30

31

 

The jenkins home directory should look similar to below. The jenkins home directory information is available in the above configuration file.

 

33

 

Start/Stop/Restart

 

To know the status of jenkins, run the below command.

sudo service jenkins status

 

34

If the jenkins is running without issues, then you can see the status as ‘active’ in the Active field in the above message. It also indicates when it was last started and how long it is running since last restart.

 

35

If the jenkins is stopped, then the Active field indicates ‘inactive’ along with the information on when it was shutdown.

 

You can run the below command to start jenkins.

 

sudo service jenkins start

Run the below command to stop jenkins.

sudo service jenkins stop

Run the below command to restart jenkins.

sudo service jenkins restart

36

 

Initial Jenkins Run

 

Once jenkins is installed successfully and you confirmed it is running successfully, open the jenkins url in browser to start configuring jenkins and using it.

 

Browse to <your host ip address>:8080 to open jenkins. Replace <your host ip address> with your ubuntu system ip.

 

You will see the below page when you access jenkins for the 1st time. It asks for one time Administrator password which is available at the below location on the machine jenkins is installed.

 

/var/lib/jenkins/secrets/initialAdminPassword

 

The path of the password file is indicated in the initial Jenkins page displayed when jenkins is accessed for 1st time.

 

37

 

Open the initialAdminPassword file and copy the password and paste it in the ‘Unlock Jenkins’ page and click on ‘Continue’.

image

 

The plugins used by Jenkins can be configured in the below page. Select ‘Install suggested plugins’ to stick with the default plugins suggested by Jenkins. You can manage the plugins at any point of time from Jenkins UI, so continue with the suggested plugins.

 

image

 

Jenkins will install the selected plugins.

 

image

 

After the plugins are installed, you can create the first admin user which can be used to manage Jenkins.

 

image

 

Provide username, password, full name, email id and click on ‘Save and Continue’ to create Jenkins admin user.

image

 

You can configure the jenkins url from the below screen. This can also be changed at any point of time, so leave it to the suggested value and click on ‘Save and Finish’.

image

 

Configuring Jenkins is now complete. Click on ‘Start using Jenkins’ to view the Jenkins home page.

 

image

 

The jenkins home page for the admin user created earlier is displayed.

image

 

Uninstall

 

Stop Jenkins service before uninstalling it. Then run the below command to uninstall jenkins

 

sudo apt-get remove --purge jenkins

Type ‘y’ when asked for confirmation.

 

image

 

Conclusion

 

In this post, we learnt how to install, run, configure and uninstall jenkins on Ubuntu. The later processes of creating and running jobs is same irrespective of where the jenkins instance is running.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s