Jenkins: Install Jenkins on Redhat 9 with OpenJDK 17

From Wiki

Install Jenkins on Redhat 9 with OpenJDK 17

Install Jenkins

1) Configure Jenkins repository

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-2023.key
sudo yum upgrade

2) Add required dependencies for the jenkins package

sudo yum install fontconfig java-17-openjdk
sudo yum install jenkins
sudo systemctl daemon-reload

3) Configure to use java-17-openjdk

In my case I need to have java-11 and java-17 on RedHat, i will configure Jenkins service to use jdk 17

I prefere to use vim as system editor

export SYSTEMD_EDITOR=vim

Edit

systemctl edit jenkins --full

Uncomment and define JAVA_HOME

Environment="JAVA_HOME=/usr/lib/jvm/java-17-openjdk"

Save and Quit

4) Start and enable Jenkins service using following commands

sudo systemctl start Jenkins
sudo systemctl status jenkins

Optional 5) Configure Firewall

sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload

Configure

1) Open your browser and access Jenkins Web Interface

http://your_server_ip_or_domain:8080

2) Get initial password

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

and add put in browser

3) Install Suggested Plugins

4) Create a admin user

5) Save and finish

Using Jenkins

1) Create a new Job

Demo Job

2) On Build Steps, click on Add Build Step and choose Execute Shell.

3) Add the following code

#!/bin/bash

echo "dummy test jenkins"

Save

4) On Demo Job, click in Build Now.

5) After run, click in Console Output.

Ver também