Jenkins Installation
Pre-requisites
Configure JAVA_HOME
on Windows:
- Right click My Computer and select Properties
- On the Advanced tab, select Environment Variables
- Edit
JAVA_HOME
to point to where the JDK software is located - For example,
C:\Program Files\Java\jdk1.6.0_02
Configure Java_Home on Linux:
-
Login to your account and open the startup script file
-
The script is usually
~/.bash_profile
file -
It can also be the .bashrc depending on your envrionment settings
vi ~/.bash_profile
-
In the startup script, set
JAVA_HOME
andPATH
setenv JAVA_HOME jdk-install-dir
setenv PATH $JAVA_HOME/bin:$PATH
export PATH=$JAVA_HOME/bin:$PATH -
jdk-install-dir is the JDK installation director, which should be something similar to /usr/java/jdk1.5.0_07/bin/java
-
Bourne shell:
JAVA_HOME=jdk-install-dir
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH -
Korn and bash shells:
export JAVA_HOME=jdk-install-dir
export PATH=$JAVA_HOME/bin:$PATH
-
-
Type the following command to activate the new path settings immediately:
source ~/.bash_profile
-
Verify new settings:
echo $JAVA_HOME
echo $PATH
Install using Ansible
Reference: Official Jenkins documentation..
The outline of the steps are:
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum upgrade
sudo yum install epel-release java-11-openjdk-devel
sudo yum install jenkins
sudo systemctl daemon-reload
From the outline above, we build our playbook piece by piece. After some trial and error, I have arrive to this final playbook.
# installs jenkins
---
- name: Install jenkins
hosts: jenkins
become: true
tasks:
- name: Download files
get_url:
url: https://pkg.jenkins.io/redhat-stable/jenkins.repo
dest: /etc/yum.repos.d/jenkins.repo
- name: Download apt_key
ansible.builtin.rpm_key:
key: https://pkg.jenkins.io/redhat-stable/jenkins.io.key
state: present
- name: Upgrade all packages
yum:
name: '*'
state: latest
- name: Ensure epel repo is present
yum:
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
state: present
- name: Install Jenkins and Java using yum
yum:
name:
- jenkins
- java-11-openjdk-devel
state: present
- name: Force systemd to reread configs
systemd:
daemon_reload: yes
- name: Ensures Jenkins is started
systemd:
name: jenkins
enabled: yes
state: started
# Uncomment play below if you have firewalld
# - name: FirewallD rules
# firewalld:
# permanent: yes
# immediate: yes
# service:
# - jenkins
# - http
# port: 8080/tcp
# zone: public
# state: enabled
To run the playbook:
ansible-playbook install-jenkins-on-lb1.yml
Once it's done, get the IP of the machine and paste it to your web browser, followed by ":8080".
http://13.228.99.157:8080/
During the first time, Jenkins will display a Getting Started page where you will need to follow an instruction. Paste the password in the field.
On the next page, you're given a choice to select the plugins to install or go with the suggested ones. For now we'll go with the suggested plugins.
After the plugins are installed, Jenkins will now prompt you to create the first admin user.
Next, you will need to configure the URL. Afterwards click Save and Finish.
http://13.228.99.157:8080/jenkins-lab
Install using Docker
This section outlines how to set up Jenkins using Docker, providing a quick and efficient way to run Jenkins in a containerized environment.
# docker-compose-jenkins.yml
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- $PWD/jenkins_home:/var/jenkins_home
networks:
- net
networks:
net:
Steps to Install Jenkins using Docker
-
Save YAML configuration as
docker-compose-jenkins.yml
. -
Open a terminal and navigate to the directory containing the YAML file.
-
Execute the following command to start Jenkins:
docker-compose up -d
Access the Jenkins UI
After you install Jenkins, you can access the Jenkins portal:
-
Open a web browser and go to
http://localhost:8080
. -
This will load the Jenkins setup page.
-
Retrieve the initial admin password by running:
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
-
Copy the password and paste it into the setup page to unlock Jenkins.
-
Follow the instructions to install recommended plugins and set up your admin user.
-
Once the setup is complete, you can now start creating jobs.