Install Jenkins and configure for first time use on Windows Server/ Ubuntu/ CentOS

As you might be aware, Jenkins is an open-source software originally forked from Hudson. Jenkins is very much popular in DevOps community as it intends to automate software development part for continuous integration and continuous delivery and supports various source code management tools. There are a number of plugins available to not only build code in different programming languages, but also to execute scripts on various OS platforms, perform automated testing etc. In this post, we’ll explore how to install and setup Jenkins for first time usage on various Operating System platforms.

Installation on Windows Server:

This makes use of Chocolatey package manager. You need to have administrative privileges on the windows server in reference. First, make sure that execution policy to RemoteSigned. This should be standard on Windows Server 2012 R2 or higher. Else you can use Set-Execution policy for this:

Set-ExecutionPolicy RemoteSigned -Confirm:$false

To install Chocolatey, open a PowerShell prompt with administrative privileges, and run below command:

iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

After this, we need to install JDK8 using below command:

choco install jdk8 -y

and jenkins using below command:

choco install jenkins -y

This summarizes our overall commands as:

# Configures execution policy to remotesigned
if($(Get-ExecutionPolicy) -ne "RemoteSigned"){
Set-ExecutionPolicy RemoteSigned -Confirm:$false
}
# Installs chocolatey package manager
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
# Installs JDK8 using chocolatey
choco install jdk8 -y
# Installs jenkins ci using chocolatey
choco install jenkins -y

Installation on Ubuntu:

You need to have sudo access to the ubuntu server for this. First, we would install jdk and jre using below command:

sudo apt-get update

sudo apt-get install openjdk-8-jre

sudo apt-get install openjdk-8-jdk

You can check if jvm is installed properly using java -version.

In order to help Java-based applications locate the Java virtual machine properly, you need to set two environment variables: “JAVA_HOME” and “JRE_HOME”:

export JAVA_HOME=’/usr/lib/jvm/jre-1.8.0-openjdk’
export JRE_HOME=’/usr/lib/jvm/java-8-openjdk-amd64/jre’

After this, run below commands one at a time (Credit goes to https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu):

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

This makes for a overall script as below:

#update list of repositories
sudo apt-get update
#install jre and jdk
sudo apt-get install openjdk-8-jre
sudo apt-get install openjdk-8-jdk
#set export variables for java
export JAVA_HOME='/usr/lib/jvm/jre-1.8.0-openjdk'
export JRE_HOME='/usr/lib/jvm/java-8-openjdk-amd64/jre'
#install jenkins on debian based distributions such as ubuntu
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
#configures jenkins service to start at run time
sudo systemctl start jenkins.service
sudo systemctl enable jenkins.service

Installation on CentOS:

First install the latest packages to keep system update:

sudo yum update

sudo reboot

Then we need to install jdk on the system:

sudo yum install java-1.8.0-openjdk.x86_64

You can check if jvm is installed properly using java -version.

In order to help Java-based applications locate the Java virtual machine properly, you need to set two environment variables: “JAVA_HOME” and “JRE_HOME”:

export JAVA_HOME=’/usr/lib/jvm/jre-1.8.0-openjdk’
export JRE_HOME=’/usr/lib/jvm/java-8-openjdk-amd64/jre’

We can install Jenkins now using below commands one at a time:

cd ~
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
sudo rpm –import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
sudo yum install jenkins

This makes for our overall script as:

#update list of repositories
sudo yum update
sudo reboot
#install jdk
sudo yum install java-1.8.0-openjdk.x86_64
#set export variables for java
export JAVA_HOME='/usr/lib/jvm/jre-1.8.0-openjdk'
export JRE_HOME='/usr/lib/jvm/java-8-openjdk-amd64/jre'
#install jenkins on rpm based distributions such as centos
cd ~
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
sudo yum install jenkins
#configures jenkins service to start at run time
sudo systemctl start jenkins.service
sudo systemctl enable jenkins.service
#configures firewall to allow connections on port 8080
sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

Do note that you need to add the export commands to the shell startup scripts so they can get added every time the server is rebooted.

Configuring Jenkins for first time use:

We need to connect to Jenkins using server’s ip address. For this, we can use ipconfig in windows, ifconfig in ubuntu or ip addr in centos on the command/bash. Once we have the ip address, open your browser on your desktop, type http://:8080. Don’t forget the :8080 part as this is default port for Jenkins.

Once you hit the url, you would be greeted with an initial screen for default password and path to password file would be mentioned in the console.

For windows users:

Initial password screen for Jenkins in Windows Server
Initial password screen for Jenkins in Windows Server

And for linux users:

initial-password-screen-for-jenkins
Initial password screen for Jenkins in Linux distributions

Needless to say, you need to read content of the file and enter the password. Note that you will need to take ownership of the said file before you can read it in linux distributions using sudo chown. After this, enter the password in the window and click next. In the next screen, select plugins to install:

Select plugins to install in Jenkins - 01
Select plugins to install in Jenkins – 01

In the next screen presented, select none first and then select install (this will make sure that we do not install any plugin to start with):

select-plugins-to-install-in-jenkins-02
Select plugins to install in Jenkins – 02

In the next screen, click start using jenkins. Then from ribbob, click on your username (which is by default named admin) and then click configure from right panel.

Change password for default user
Change password for default user

This will present you with the user properties. First thing would be to edit password to something that you can remember and in line with your organizational policies.

Logout and now login with your new password to make sure its working. Now click manage jenkins and edit global security properties:

edit-security-settings

Check box for allow new users to sign up and then click save from bottom:

allow-users-to-sign-up-in-jenkins
Allow users to sign up in jenkins

You may choose to Manage users to create few new selected users from manage jenkins option as well, instead of allowing users to sign up. This would allow for restricted access for jenkins. If Jenkins is installed on a Windows Server, you would also get option to integrate it with the directory services such as active directory.

The jenkins server is ready to use now.

One thought on “Install Jenkins and configure for first time use on Windows Server/ Ubuntu/ CentOS

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 )

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