
Jenkins is a popular open-source automation server that enables continuous integration (CI) and continuous deployment (CD) in software development. Written in Java, Jenkins allows software developers to build, test, and deploy software. It provides many plugins to automate testing and manage changes in a large code base.
This article explains how to install Jenkins on Rocky Linux 9. You'll test the installation using the Jenkins dashboard and Jenkins CLI, and optimize Jenkins for maximum performance.
Before you begin, you need to:
example.com.Jenkins requires the Java development kit to run with all necessary dependecies. Follow the steps below to install the Java Development Kit (JDK) on your Rocky Linux 9 instance.
Update the server’s package information index.
Install OpenJDK 21, or replace it with the latest version available on the OpenJDK releases page.
By default, your system may use a pre-installed older version of Java. Use the following command to check and switch to OpenJDK 21:
If your system has multiple versions of Java, you will see an output like the one below:
Type 2 to select OpenJDK 21.
Verify the installation.
Output:
Follow the steps below to install Jenkins on your Rocky Linux 9 workstation using the DNF package manager.
Add the latest stable Jenkins repository to your DNF sources.
Find the GPG key for your version from the same page and install it.
Install Jenkins.
Start the Jenkins service.
Enable the Jenkins service to Start on Boot.
Check its status.
Output:
Follow the steps to access the Jenkins web interface and complete the initial setup.
Allow the default Jenkins port 8080 through the firewall to enable web access.
Reload the firewall to apply the new rule.
Access the initial administrative password.
The output of this command is the password. Copy it.
Open your web browser and access Jenkins using your domain name on port 8080.
Paste the copied password in the Administrator Password field, and click Continue.
Select the Install suggested Plugins to start installing all necessary Jenkins packages on your server.
It will start to install the suggested plugins.
The setup prompts you to enter the details of your first Admin User. Fill these fields and click the Save and Continue button to access the instance configuration page.
Enter or confirm the Jenkins URL, which should match your domain name.
After entering the Jenkins URL, click the Save and Finish button.
At last, click the Start using Jenkins button to access the Jenkins Dashboard.
Follow the steps below to install Nginx as a reverse proxy and generate Let's Encrypt SSL certificates using Certbot to secure the Jenkins web interface.
Install the Nginx web server.
Install Certbot and the Nginx plugin.
Allow HTTP traffic.
Allow HTTPS traffic.
Reload the firewall to apply changes.
Request an SSL certificate.
Certbot will present you with prompts in this sequence:
N.Your system now has a valid certificate for your domain name which it can use to establish TLS encryption for client sessions.
Enable Nginx to start on boot and start the service.
Allow Jenkins to communicate over the network by enabling the necessary permissions.
Open the Nginx configuration file.
Add the following configuration.
Save and close the file.
In the jenkins.conf file, do not add https:// or / to your domain name in the server_name directive.
Test the Nginx configuration.
Output:
Restart Nginx to apply the changes.
Open your browser and go to:
Jenkins should now be accessible over a secure HTTPS connection.
To avoid a proxy setup error, change the Jenkins URL to HTTPS by navigating to Manage Jenkins > System in the Jenkins dashboard. Scroll down to the Jenkins Location section, update the Jenkins URL field from http://example.com:8080 to https://example.com/, and click the Save button to apply the changes.
Restart Jenkins and apply the new URL setting.
You can improve Jenkins's performance by adjusting system limits.
Follow the steps below to adjust system settings and allow Jenkins to handle more tasks.
Open the limit configuration file.
Add the following lines before the #End of file comment to increase the maximum number of open files Jenkins can handle. It will prevent resource limitations that could affect Jenkins's performance under heavy workloads.
Save and close the file.
Restart Jenkins to apply the changes.
Verify if the limits are applied.
Output:
Setting up regular backups can prevent data loss. Follow the steps below to back up Jenkins and automate the process.
Create a folder to store backups.
Copy Jenkins data to the backup folder. This command copies all Jenkins configuration files, jobs, and user data.
To schedule automatic daily backups, edit your cron jobs.
Add the following line at the button to run the backup every day at midnight.
Save and exit the file.
Check if the cron job was saved by running:
If you see the backup job listed, it is set up.
Verify the status of the cron service.
Output:
If the status is active, your backup job will run as scheduled.
Open Jenkins in your browser and sign in to the dashboard.
Click the New Item button from the dashboard sidebar. Enter a job name, such as TestJob, and select the Freestyle Project option under the item type section, and click OK.
Scroll to the Build Step section and select Add build step > Execute shell.
Then, enter the following command:
Click Save to apply the changes.
Click Build Now to start the job.
Click the Build, for example, #1, to open the details.
Click Console Output to view the build logs.
If you see this message, your Jenkins setup is successful.
You can also verify the functionality of your Jenkins installation through the command line. This method uses Jenkins REST API and the Jenkins CLI.
From the Jenkins dashboard, click your username in the top right corner and navigate to the Security tab.
Under the API Token section, click Add New Token, enter a token name, and click Generate. Copy and save the token in a secure location.
Download the Jenkins CLI jar file.
Replace example.com with your actual domain name.
Move the Jenkins CLI jar file to a suitable location.
Run the following command to check the connection.
Replace your_username with your Jenkins username and your_api_token with your API token.
Output:
Trigger the Test Job
Wait a few moments for the build to complete.
View build console output.
Output:
You have set up Jenkins on a Rocky Linux 9 instance and configured it for secure access. You created a sample job to verify its functionality and used the Jenkins CLI to manage jobs from the command line. You can now integrate Jenkins with version control systems, automate deployments, and scale your setup as needed. For advanced configurations and plugin options, refer to the Jenkins documentation.
0 Comments
Be the first to comment and share your perspective with the community.