Jenkins
Overview​
This installation happens on the
dsb-hub
.
According to Jenkins User Documentation, Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software. It's a CI/CD platform.
Prerequisites​
- Install Java
Before installing Jenkins, ensure that Java is installed on your system:
-
Update your package manager and install Java:
sudo apt update
sudo apt install fontconfig openjdk-17-jre
Installation Steps​
- Configure the Package Manager and Install Jenkins
-
Add Jenkins to your package manager by downloading and installing the Jenkins key:
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
-
Add the Jenkins repository to your sources list:
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
-
Update your package list and install Jenkins:
sudo apt-get update
sudo apt-get install jenkins
- Enable and Start Jenkins
-
Enable Jenkins to start on boot:
sudo systemctl enable jenkins
-
Start Jenkins:
sudo systemctl start jenkins
- Verify Jenkins is Running
-
Check the status of Jenkins to ensure it's active:
sudo systemctl status jenkins
-
You should see output similar to the following if Jenkins is up and running:
â—Ź jenkins.service - Jenkins Continuous Integration Server
Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; preset: enabled)
Active: active (running) since [DATE]; [TIME] ago
Main PID: 9188 (java)
Configuration Steps​
- Access Jenkins via Web Browser
-
Open your web browser and go to:
http://your_ip:8080
-
You should see the Jenkins setup screen.
- Retrieve the Initial Admin Password
-
To proceed with the setup, you will need the initial admin password. Retrieve it by running the following command on your server:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
-
Copy the password and enter it in the password box on the web interface.
- Install Suggested Plugins
-
After entering the admin password, click Install suggested plugins and allow Jenkins to install the necessary plugins.
- Set Up Your Admin Account
-
After the plugins are installed, you’ll be prompted to set up your admin account. Enter your IP details and set up your Jenkins instance.
- Configure Instance IP
-
After you enter your admin information, set the URL IP address of your instance or press
Not Now
.
- Navigate to the home page
-
You should be here now.
Installing Jenkins Node​
This section covers installing and configuring a Jenkins node on
dsb-node-01
.
- Create Jenkins User
-
Create a Jenkins user and set appropriate permissions:
sudo adduser jenkins
sudo chown -R jenkins:jenkins /home/jenkins
sudo chmod 755 /home/jenkins
sudo usermod -aG docker jenkins
- Install Java
-
Install Java on the Jenkins node:
sudo apt install openjdk-17-jre-headless
- Configure the Jenkins Node in Jenkins UI
-
In Jenkins UI, navigate to Dashboard > Manage Jenkins > Nodes. Click on New Node. Select Permanent Agent and click OK.
-
For your agent, configure the Remote root directory to
/home/jenkins/agent
and save the configuration.
- Configure Jenkins Security for Agents
-
In Jenkins UI, navigate to Dashboard > Manage Jenkins > Security, and scroll down until you see TCP ports for inbound agents. Select Random. Apply/Save.
- Set Up the Jenkins Node
-
On
dsb-node-01
, create the agent directory:cd /home/jenkins && mkdir agent
-
Download the Jenkins agent JAR file:
wget http://<jenkins-server-url>/jnlpJars/agent.jar
-
Run the Jenkins agent:
java -jar agent.jar -jnlpUrl http://<jenkins-server-url>/computer/<node-name>/slave-agent.jnlp -secret <secret-key> -workDir "/home/jenkins/agent"
NOTE: You can find the secret key on the Jenkins node configuration page.
- Create a Systemd Service for the Jenkins Agent
-
Create a new systemd service for the Jenkins agent:
sudo nano /etc/systemd/system/jenkins-agent.service
-
Add the following configuration to the service file:
[Unit]
Description=Jenkins Agent
[Service]
User=jenkins
Group=jenkins
ExecStart=/usr/bin/java -jar /home/jenkins/agent/agent.jar -jnlpUrl http://<jenkins-server-url>/computer/<node-name>/slave-agent.jnlp -secret <secret-key> -workDir /home/jenkins/agent
Restart=always
[Install]
WantedBy=multi-user.target -
Reload systemd and start the Jenkins agent service:
sudo systemctl daemon-reload
sudo systemctl start jenkins-agent
sudo systemctl enable jenkins-agent
You're Done​
You're finished setting up Jenkins on your machine!