Installing Jenkins Opensource

Jenkins is an automation server written in “Java” and has an embedded servlet container/application server built-in “Jetty”

Jetty is developed and maintained by eclipse.org. It Provides a web server and javax.servlet container. It has impressive support for HTTP/2, WebSocket, OSGi, JMX and many other integrations

It is also very simple to use Jetty alternatives like Apache Tomcat (or) Glassfish to host Jenkins.

System Requirements

Jenkins environment sizing depends on many factors. Sometimes achieve a correct configuration requires experimentation and experience. However below mentioned are some of the best practices to keep in mind for smart approximation of system requirements.

As an organization matures from a continuous delivery standpoint, its Jenkins requirements will similarly grow. This growth is often reflected in the Jenkins master’s architecture, whether that be “vertical” or “horizontal” growth.

Vertical growth is when a master’s load is increased by having more configured jobs or orchestrating more frequent builds. This may also mean that more teams are depending on that one master.

Horizontal growth is the creation of additional masters within an organization to accommodate new teams or projects, rather than adding these things to an existing single master.

It is always highly recommended to follow horizonal growth and by enabling distributed builds architecture.

Resource requirements of Jenkins master

The amount of compute resource that master needs depends on many factors. Memory sizing can vary from 1GB to 20+GB. In general, it is a bad practice to allocate executors on a master, as builds can quickly overload a master’s compute resources and could become a single point of failure causing unnecessary downtime and huge startup times.

Adding multiple agents to master OnDemand is the recommend option to offload Jenkins master with builds. Each build node connection will take 2-3 threads, which equals about 2 MB or more of memory. You will also need to factor in CPU overhead for Jenkins if there are users who will be accessing the Jenkins user interface.

Hidden Options

Before we proceed with installation, lets us talk about hidden features and how to enable to enable them with JAVA_OPTS. System properties are defined by passing -Dproperty=value to the java command line to start Jenkins.

-Dhudson.footerURL=https://www.servana.app

Set Content Security Policy header sent for static files served by Jenkins as false.

-Dhudson.model.DirectoryBrowserSupport.CSP=

Set Time zone for Jenkins

-Duser.timezone=Europe/London

Enable Start-up performance logging

-Djenkins.model.Jenkins.logStartupPerformance=true

Enable Java Min and Max memory thresholds to Jenkins

'-Xms2048m -Xmx3000m'

(Complete list of features controlled by system properties are available in link.)[https://wiki.jenkins.io/display/JENKINS/Features+controlled+by+system+properties]

Likewise some of the key plugins have hidden features that can be enabled through JAVA Options.

Over Provisioning of Jenkins agents

By default, Jenkins spawns agents conservatively. Say, if there are 2 builds in queue, it won’t spawn 2 executors immediately. It will spawn one executor and wait for some time for the first executor to be freed before deciding to spawn the second executor. Jenkins makes sure every executor it spawns is utilized to the maximum. If you want to override this behaviour and spawn an executor for each build in queue immediately without waiting, you can use these flags during Jenkins start-up:

-Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85

S3 Artifact manager - Delete artifacts

Dio.jenkins.plugins.artifact_manager_jclouds.s3.S3BlobStoreConfig.deleteArtifacts=true

S3 Artifact manager - Delete stash

Dio.jenkins.plugins.artifact_manager_jclouds.s3.S3BlobStoreConfig.deleteStashes=true

Prerequisites

Remove old versions of java installations and install (Java 1.8+)[https://java.com/en/download/manual.jsp]

Jenkins installation through war file:

Download the Web application ARchive (WAR) file of the respective Jenkins version of interest from (link for Jenkins stable war file)[http://mirrors.jenkins.io/war-stable/]. It is always recommended to download the latest version, as it has all the security fixes and newly released features.

This installation steps work on any operating system or platform that supports Java 1.8+.

  1. Open up a terminal/command prompt window to the download directory.
  2. Run the command java -jar jenkins.war.
  3. Browse to http://localhost:8080 and wait until the Unlock Jenkins page appears.
  4. Continue with post installation steps.

Step-2 in the above mentioned list is where you can pass the hidden features as java options.

Jenkins installation on Mac OS

Download the Mac archive (PKG) file of the respective Jenkins version of interest from (link to Jenkins for Mac OS)[http://mirrors.jenkins.io/osx/]. Open the file and proceed with installation wizard.

(or)

Installation through brew is as simple as below;

brew install jenkins-lts

Jenkins Installation on Debian/Ubuntu

On Debian-based distributions, such as Ubuntu, you can install Jenkins through apt. Recent versions are available in an apt repository. Older but stable LTS versions are in this apt repository.

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install jenkins

Jenkins Installation on Windows

Download the zip file from link to Jenkins for Windows of the respective Jenkins version of interest and follow the package installation wizard.

Jenkins Installation on Docker:

One command does everything.

docker run --name jenkins -v $(pwd):/var/jenkins_home -p 8080:8080 -p 50000:50000 --env JAVA_OPTS=-Dhudson.footerURL=http://www.servanamanaged.com jenkins/jenkins:lts

Post-installation setup wizard:

After downloading, installing and running Jenkins using one of the procedures above, the post-installation setup wizard begins. This setup wizard takes you through are a few quick “one-off” steps to unlock Jenkins, customize it with plugins and create the first administrator user through which you can continue accessing Jenkins.

Unlocking Jenkins

When you first access a new Jenkins instance, yo

  1. Browse to http://localhost:8080 (or whichever port you configured for Jenkins when installing it) and wait until the Unlock Jenkins page appears.

  2. From the Jenkins console log output, copy the automatically-generated alphanumeric password (or) open the file located in /var/Jenkins_home/secrets/initialAdminPassword.

  3. On the Unlock Jenkins page, paste this password into the Administrator password field and click Continue.

Customizing Jenkins with plugins

After unlocking Jenkins, the Customize Jenkins page appears. Here you can install any number of useful plugins as part of your initial setup.

Click one of the two options shown

• Install suggested plugins - to install the recommended set of plugins, which are based on most common use cases. • Select plugins to install - to choose which set of plugins to initially install. When you first access the plugin selection page, the suggested plugins are selected by default.

The setup wizard shows the progression of Jenkins being configured and your chosen set of Jenkins plugins being installed. This process may take a few minutes.

Creating the first administrator user

Finally, after customizing Jenkins plugins, Jenkins asks you to create your first administrator user.

  1. When the Create First Admin User page appears, specify the details for your administrator user in the respective fields and click Save and Finish.
  2. When the Jenkins is ready page appears, click Start using Jenkins.
  3. If required, log in to Jenkins with the credentials of the user you just created and you are ready to start using Jenkins!

Tips for Automating Post installation Steps

  1. Disable Java option JAVA_OPTS -Djenkins.install.runSetupWizard=false
  2. List all plugins in file and pass the file as input to below script /usr/local/bin/install-plugins.sh
  3. Create admin users as the post initialisation groovy script. More details are available in below (link)[https://wiki.jenkins.io/display/JENKINS/Post-initialization+script].

If you would rather leave managing Jenkins to the experts then checkout our Jenkins-as-a-service.