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.

Installing Java 8 on Ubuntu

 

First check if Java is already installed on the system. Run the below command to check if Java is already installed on the system.

 

java –version

 

If java is not installed on the system, you should see message similar to below.

1

 

If the java is already installed on the system, then it should display the version of java installed on the system.

 

11

 

If java is not installed on the system, then run the below command to start java installation.

sudo add-apt-repository ppa:webupd8team/java

Press [ENTER] to add the java repository information to the system.

2

3

 

Once java repository information is added, run the below command to update the package lists since java package is added to the list earlier.

 

sudo apt update

 

4

 

Run the below command to download and install java 8.

 

sudo apt install oracle-java8-installer

 

Enter ‘Y’ when the installer asks for confirmation to start java installation.

5

 

Select ‘Ok’, when the installer asks for accepting the java license.

 

6

 

Select ‘Yes’ when the  installer asks for accepting the Oracle license.

 

7

 

The download and installation of Java will take some time.

8

9

10

 

Run the below command to set the java version we have installed as the default version.

 

sudo apt install oracle-java8-set-default

 

12

Once the installation of java is complete, run the java version command again to check the java version.

 

java –version

 

11

 

 

Conclusion

 

java 8 (including JDK) is installed on Ubuntu and can be used for developing or running java applications.

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.

Fixing FileUploadBase$SizeLimitExceededException on Tomcat.

 

Mostly when doing hot deployments of web applications through manager on Tomcat, the hot deployment may fail with reason similar to below.

 

SEVERE [http-nio-8080-exec-2] org.apache.catalina.core.ApplicationContext.log HTMLManager: 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)]
java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (75715094) exceeds the configured maximum (52428800)
    at org.apache.catalina.connector.Request.parseParts(Request.java:2890)
    at org.apache.catalina.connector.Request.parseParameters(Request.java:3185)
    at org.apache.catalina.connector.Request.getParameter(Request.java:1116)
    at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381)
    at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:109)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:607)
    at org.apache.catalina.valves.RequestFilterValve.process(RequestFilterValve.java:348)
    at org.apache.catalina.valves.RemoteAddrValve.invoke(RemoteAddrValve.java:52)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (75715094) exceeds the configured maximum (52428800)
    at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:805)
    at org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:256)
    at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:280)
    at org.apache.catalina.connector.Request.parseParts(Request.java:2846)
    … 28 more

 

This is because the max file size that can be uploaded through manager app is set to 50MB, and your war file size is larger than the 50 MB.

This limit can be modified in web.xml file available at <Your Tomcat Root Folder>\webapps\manager\WEB-INF. If you open the web.xml, you should find configurations similar to below.

 

<servlet>
    <servlet-name>HTMLManager</servlet-name>
    <servlet-class>org.apache.catalina.manager.HTMLManagerServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>

  <!– Uncomment this to show proxy sessions from the Backup manager or a
       StoreManager in the sessions list for an application
  <init-param>
    <param-name>showProxySessions</param-name>
    <param-value>true</param-value>
  </init-param>
  –>
    <multipart-config>
      <!– 50MB max –>
      <max-file-size>52428800</max-file-size>
      <max-request-size>52428800</max-request-size>

      <file-size-threshold>0</file-size-threshold>
    </multipart-config>
  </servlet>

 

Change the max-file-size and max-request-size to a larger value. The value is in Bytes, so convert the value you want to configure into bytes. So if you want to configure 100 MB, then the value should be 100*1024*104 = 104857600. So the new configuration will look similar to below.

 

<servlet>
  <servlet-name>HTMLManager</servlet-name>
  <servlet-class>org.apache.catalina.manager.HTMLManagerServlet</servlet-class>
  <init-param>
    <param-name>debug</param-name>
    <param-value>2</param-value>
  </init-param>
  <!– Uncomment this to show proxy sessions from the Backup manager or a
       StoreManager in the sessions list for an application
  <init-param>
    <param-name>showProxySessions</param-name>
    <param-value>true</param-value>
  </init-param>
  –>
  <multipart-config>
    <!– 100MB max –>
    <max-file-size>104857600</max-file-size>
    <max-request-size>104857600</max-request-size>

    <file-size-threshold>0</file-size-threshold>
  </multipart-config>
</servlet>

Once the modification is saved, restart the tomcat for the settings to apply and then should be able to deploy a war file up to 100 MB without any issues. The value can be changed based on the size of war files that you normally deploy.

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.