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.

Creating New Users on Jenkins

 

New users on Jenkins can be created  in a couple of ways.

 

Add User:

 

An existing user can create a new user from Manage Jenkins –> Manage Users –> Create User.

 

image

 

image

 

Enter the username, password, name and email address and click on ‘Create User’ to create a new user.

 

image

 

image

 

image

 

User Registration:

 

In the other way, new users can register themselves on Jenkins instance.

 

image

 

To Allow new users to register themselves on  Jenkins, select Manage Jenkins –> Configure Global Security.

 

Select ‘Enable security’ and in Security Realm section, select ‘Jenkins own user database’ and select ‘Allow users to sign up’ option.

image

 

This will enable the ‘create an account’ option on the Jenkins login page.

 

image

 

Click on ‘create an account’ and provide username, name, email id and password and ‘Create account’.

 

image

 

image

 

Conclusion

In this section, we created new users on Jenkins.

Installing Jenkins on Mac

 

Download

 

Download the jenkins installer from the below link.

https://jenkins.io/download/

Click on the Mac OS X to download.

image

 

image

 

The Jenkins installer for mac is downloaded.

image

 

Installation

For Jenkins, Java needs to be installed on the system, since Jenkins is written in Java. So check if Java  is installed on the system by running the below command.

java –version

It should return java version information similar to below.

image

 

If java information is not returned, then java is not installed on the system, so install Java first before continuing to the next step.

 

Double click on the downloaded Jenkins installer to launch the installer.

 

Click on ‘Continue’ to start the installation process.

image

 

Click on ‘Continue’ to accept the license and continue to installation.

 

image

 

Click on ‘Agree’ to agree to license terms and continue installation.

 

image

 

The installer asks information regarding which users of the system do you want Jenkins to be installed for. You can leave the default provided and click on ‘Continue’.

image

 

You can change the jenkins installation location by clicking on ‘Change Install Location’, or you can leave the default installation location and click on ‘Install’ to start installing Jenkins.

 

image

 

Enter your mac user name and password to click on ‘Install Software’ to start Jenkins installation.

 

image

 

The installation will take some time to complete.

 

image

 

Click on ‘Close’ once the installation is complete.

 

image

 

Click on ‘Move to Trash’ if you want to delete the Jenkins installer downloaded and used for installation. If you don’t want to delete it, click on ‘Keep’.

 

image

 

The jenkins is installed at the below location.

 

Users/Shared/Jenkins

 

The jenkins installation folder should look similar to below.

 

image

 

Configuration

 

Once the jenkins installation is complete, it opens the below page on the web browser. You need to enter to temp admin password provided by Jenkins to start configuring the jenkins and creating the users on jenkins.

 

The location of the temp password file is provided in the same page below. It is supposed to be at ‘/Users/Shared/Jenkins/Home/secrets/initialAdminPassword’.

 

image

 

Navigate to that location, to open the password file. But as you can see in the below screen shot, there are no files in the secrets folder.

 

image

 

Actually the files are there, but we cant see them. You need to change permissions to view the files in the secrets folder. Follow the below steps to change the permissions.

 

Right click on the secrets folder and select ‘Get Info’ option.

 

image

 

Enter the mac system user name and password to open the information regarding the secrets folder.

image

 

The information regarding the secrets folder is displayed.

 

image

 

Click on the lock symbol at the bottom right side corner of the secrets info view.

 

Enter the mac system user name and password to continue to modify the secrets folder permissions.

 

image

 

The list of the available users and groups on the mac are displayed.

 

image

 

select the user name you used to log into mac and click on ‘Select’ button.

image

 

The user you selected is added to the ‘Sharing & Permissions’ section of the secrets info screen and it indicates that the user you selected has ready only permissions now. Now click on settings button in middle at the bottom of the secrets info view and select ‘Apply to enclosed items’ to save the modifications.

 

image

 

Click on ‘OK’ to save the modifications.

image

 

Now the files inside the secrets folder are displayed and you can see the initialAdminPassword file also inside the secrets folder. Open the initialAdminPassword file and copy the password inside it.

 

image

 

Paste the initial password into ‘Unlock Jenkins’ screen and click on ‘Continue’.

image

 

The jenkins installation is not able to connect to the plugin repository, but they can always be added/removed at any time, so click on ‘Skip Plugin Installations’ to continue configuring Jenkins.

 

image

 

You can create your first admin user for Jenkins.

 

image

 

Provide user name, name and password and click on ‘Save and Continue’ to create a admin user.

 

image

 

The jenkins url can be modified, if needed. This can be changed later if needed, so leave it as it is, and click on ‘Save and Finish’.

image

 

The jenkins installation and configuration is complete and ready for use. Click on ‘Start using Jenkins’.

image

 

The home view of the user you created is displayed.

 

image

 

 

Restart

 

To stop the jenkins service, run the below command in the terminal.

sudo launchctl unload /Library/LaunchDaemons/org.jenkins.ci.plist

To start the jenkins service, run the below command in the terminal.

sudo launchctl load /Library/LaunchDaemons/org.jenkins.ci.plist

 

You may need to enter the mac password to stop/start the jenkins after running the above stop/start commands.

 

image

 

Uninstall

 

Jenkins can be uninstalled running the below command in the terminal.

 

sudo /Library/Application\ Support/Jenkins/Uninstall.command

 

image

 

Conclusion

 

In this post, we have how to install, Configure, Restart and Uninstall Jenkins on Mac OS X. Once the Jenkins installation is complete, the projects creating builds, pipelines etc is same on all the environments, which we discuss in later posts.

Deploying Jenkins in Tomcat

 

Download

The latest version of the Jenkins can be downloaded from the below.

https://jenkins.io/download/

The LTS version receives updates every 12 weeks while the Weekly version receives an update every week, which might be an overkill to maintain. So download the Long Term Support (LTS) version.

Select the download for the environment you are going to install Jenkins on.

 

 

a0

Since we want to deploy Jenkins in Tomcat., download the Generic Java package (.war).

 

Installation

 

Since you are planning to deploy Jenkins in Tomcat, the Java and Tomcat must already be installed on your machine. Download the war file from the Jenkins download link.

 

a1

 

The Jenkins can be hot deployed into Tomcat using the Tomcat manager page.  Access the tomcat manager page through the below url.

http://localhost:8080/manager/html

If you are accessing the tomcat remotely replace localhost with the server dns.

Provide the manager user name and password to access the manager page.

image

 

The Tomcat manager page is displayed. Below ‘Applications’ section, there is a ‘Deploy’ section which provides options to do hot deployments of the web applications.

 

image

 

In ‘Deploy’ section, click on Browse and select the jenkins.war file which we downloaded at the beginning and click on Deploy.

 

image

 

image

 

The Jenkins application is deployed and you can now see it in the list of Applications.

image

 

Some times the deployment fails and the Tomcat doesn’t give much information in the web view and displays the browsers default connect reset page similar to below. This page may wary based on the browser you are using.

 

image

 

If you look up the Tomcat logs for the cause of the failure, you may find some thing similar to below.

FAIL – Deploy Upload Failed, Exception: [org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (75715094) exceeds the configured maximum (52428800)]

If this is the case, follow these steps and then redeploy the jenkins web application again.

 

If you don’t want to do hot deployment, then copy the downloaded jenkins.war file into Tomcat webapps folder and restart the Tomcat service.

 

a01

 

The Jenkins war will be extracted in the webapps folder and it should look similar to the below.

 

 

a02

 

And open the browser and type http://localhost:8080/jenkins to configuring the Jenkins. The Tomcat normally runs on 8080, but if you have configured the Tomcat to use another port, use that port to access the Jenkins app instead of the default 8080 port.

 

a2

 

If the Jenkins is installed as a service, then all the Jenkins workspace is within the Jenkins folder. But in this case, it is a deployed as webapp in Tomcat server, so the workspace is created at a different location. The Jenkins workspace will be created at C:\Users\<User Account>\.jenkins, Where <User Account> the username of the windows account with which the Tomcat is running.

 

a4

Once the Jenkins completes configuring the backend, it asks for the temporary administrator password in the Unlock Jenkins Password page. The location of the temporary password is also indicated in the same page. Enter the password from the ‘initialAdminPassword’ file and click on ‘Continue’.

a3

 

Once the initial Admin password is entered, Jenkins starts doing the configurations.

 

In Getting started page, you can select either to Install suggested Plugins, which installs some commonly used plugins or Select plugins to install, where we need to select the plugins we need. To keep it simple, we will select the Install suggested plugins. We can modify the plugins later if we need to.

 

 

15

Some of commonly used plugins are downloaded and configured.

 

a5

 

The initial Admin password provided earlier is valid only for once, so we need to create an Admin User Account.

 

a6

 

Provide the username, password, confirm password, full name and email address and click on ‘Save and Continue’.

 

a7

 

We can configure the url we want to use to access Jenkins. Let us leave the default and continue.

 

a8

 

The Jenkins set up is completed and ready to use.

 

a9

 

The Jenkins logs into the app with the admin user account you created earlier and below is the Jenkins default home view.

 

a10

 

Un-Deploying Jenkins

 

Navigate to Tomcat manager page by appending /manager/html to your tomcat url.

http://localhost:8080/manager/html.

Replace localhost with your dns if you are working remotely.

Enter the manager user name and password.

image

 

In Applications list, click on ‘Undeploy’ button against the Jenkins application.

image

 

The result of the undeploy is displayed in the Message area below the Tomcat Web Application Manager title.

 

image

 

Some times, the undeploy may not be successful, so you need to navigate to the webapps folder and delete the application folder.

image

 

If you see message like this indicating a failure with undeploying jenkins, navigate to the Tomcat webapps folder and delete the jenkins folder and then restart Tomcat.

 

Or you can try restarting Tomcat and then clicking on ‘Undeploy’ against Jenkins application in the same process again.

 

Conclusion

In this blog, we have deployed Jenkins in Tomcat, did the initial configurations and the Jenkins installation is ready for use.

Installing Jenkins as a service on Windows

Download

The latest version of the Jenkins can be downloaded from the below.

https://jenkins.io/download/

The LTS version receives updates every 12 weeks while the Weekly version receives an update every week, which might be an overkill to maintain. So download the Long Term Support (LTS) version.

image

Select the download for the environment you are going to install Jenkins on.

Since we want to install it as a service on a Windows machine, then download the Windows version.

Installation

On Jenkins download page, under ‘Download Jenkins x.xxx.x for: ‘, select Windows. A zip file is downloaded, extract it to get the Jenkins Windows Installer.

2

3

Double click on the installer to start the Jenkins installation.And click on Next to continue the installation.

4

Select the location to install the Jenkins and click on Next.

5

Click on Install to start the installation process.

6

7

8

9

Once the installation is complete, click on ‘Finish’ to complete the Jenkins installation and launch Jenkins and the browser on the system will be launched with the below page.

Configuration

10

Wait for few minutes till Jenkins completes the initial configuration needed on the first start up.

You need to provide Jenkins one time admin password to continue further setup and start using the Jenkins. The initial password will be available in the Jenkins\secrets\initialAdminPassword file inside the installation folder. The initial password file path is also provided on the same page.

11

The Jenkins installation folder looks similar to the below screen.

12

Open the initialAdminPassword file in notepad to view the one time admin password.

13

Enter the password from initialAdminPassword file into the below screen and click on Continue.

In Customize Jenkins page, you can either select to install the commonly used plugins by selecting ‘Install suggested plugins’ or if you want to select the plugins you want to install click on ‘Select plugins to install’.

15

Jenkins starts downloading the selected plugins and configuring them to your Jenkins installation.

16

Once the plugins are configured, the first admin user for Jenkins needs to be created. Provide Username, Password, Full Name, E-mail address and click on ‘Save and Continue’ to create the user.

17

18

The Jenkins url can be changed in the below screen. Let us leave it to localhost for now. We can change it at any time from the Jenkins configurations later. So just click on ‘Save and Finish’.

19

The Jenkins installation and configuration is completed. Click on ‘Start using Jenkins’ to view the Jenkins home page.

20

You are logged into the Jenkins using the first admin account you created during the configuration process and the Jenkins default home view is displayed.

21

Restart

Jenkins is installed as a service. To restart Jenkins, type ‘Windows + R’ –> services.msc, which will display the below screen. Search for Jenkins service and you can click on Stop/Restart/Start links in the left side to stop, restart or start the service.

24-8

 

Uninstall

In Control Panel, find Jenkins and click on ‘Uninstall’.

image

 

Conclusion

 

In this blog, we have installed Jenkins as a service on a Windows machine, did the initial configurations and the Jenkins installation is ready for use.