Skip to content

Install Jenkins on a VM

Consider our task is to install Jenkins on the centos-host machine and configure it to run on port 8090 instead of the default port 8080

What is Jenkins?

Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD) pipelines. It helps automate various tasks in the software development lifecycle, such as building, testing, and deploying applications.

Why Use Jenkins?

  • Automation: Jenkins automates repetitive and time-consuming tasks, freeing up developers to focus on writing code.
  • Continuous Integration: Jenkins enables frequent integration of code changes from different developers into a shared repository, catching errors early in the development process.
  • Continuous Delivery: Jenkins can automate the deployment of applications to different environments (e.g., development, testing, production), ensuring consistent and reliable delivery.
  • Flexibility: Jenkins is highly customizable with a vast ecosystem of plugins, allowing it to integrate with various tools and technologies.
  • Community and Support: Jenkins has a large and active community providing extensive documentation, support forums, and plugins.

Why is Jenkins Better?

  • Established and Reliable: Jenkins has been around for many years and is well-established, making it a trusted choice for CI/CD pipelines.
  • Large Plugin Ecosystem: The extensive plugin ecosystem allows Jenkins to integrate with almost any tool or technology, making it highly versatile.
  • Active Community: The large and active community provides excellent support, documentation, and contributions to the project.
  • Scalability: Jenkins can be easily scaled to handle complex projects and large development teams.
  • Open-Source: Being open-source, Jenkins is free to use and modify, making it accessible to organizations of all sizes.

# Install and Configure Jenkins on a CentOS VM (Port 8090)

This blog post guides you through installing Jenkins on a CentOS virtual machine (VM) and configuring it to operate on port 8090 instead of the default 8080.

Prerequisites:

  • A CentOS VM
  • SSH access to the VM
  • Root or sudo privileges

1. Install Java

Jenkins requires Java to run. Make sure the correct version is installed based on your Jenkins version requirements. Refer to the official documentation for compatibility details: https://www.jenkins.io/doc/book/installing/linux/

For this example, we'll install Java 17 OpenJDK:

sudo yum install epel-release -y
sudo yum install fontconfig java-17-openjdk -y

2. Add Jenkins Repository

Add the Jenkins repository to your Yum package manager:

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo --no-check-certificate

3. Import GPG Key

Import the Jenkins GPG key to verify the integrity of downloaded packages:

sudo rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

4. Install Jenkins

Install the Jenkins package using Yum:

sudo yum install jenkins -y

5. Configure Jenkins Port

Edit the Jenkins service file (/lib/systemd/system/jenkins.service) to change the port from 8080 to 8090:

sudo systemctl edit jenkins

In the opened file, locate the line Environment="JENKINS_PORT=" and set the value to 8090:

Environment="JENKINS_PORT=8090"

Save the changes (usually Esc then :wq in vi).

6. Start Jenkins

Start the Jenkins service to run it on the new port:

sudo systemctl start jenkins

7. Verify Jenkins Status

Check the status of the Jenkins service to ensure it's running:

sudo systemctl status jenkins

8. Initial Configuration

Note: This step requires accessing the Jenkins web interface.

Once verified, open a web browser and access Jenkins at http://<your_VM_IP_address>:8090.

The initial setup wizard will guide you through creating your first admin user and configuring additional settings. Follow the on-screen instructions to complete the setup.

Additional Considerations:

  • Firewall Rules: If a firewall is running on your VM, ensure it allows incoming traffic on port 8090 for Jenkins to be accessible.
  • Security Best Practices: Follow security best practices for Jenkins by keeping it up to date, using strong passwords, and implementing appropriate access controls.

Conclusion

By following these steps, you've successfully installed and configured Jenkins on your CentOS VM to run on port 8090. Now you can start creating and managing your CI/CD pipelines!

Other Options

While Jenkins is a popular choice, other CI/CD tools are available, each with its own strengths and weaknesses:

  • GitLab CI/CD: Built into GitLab, it offers a seamless integration with Git repositories and is well-suited for smaller teams.
  • CircleCI: A cloud-based platform known for its speed and ease of use, ideal for startups and small teams.
  • Travis CI: Another cloud-based option with a focus on simplicity and integration with GitHub.
  • Bamboo: A commercial CI/CD server from Atlassian, offering a tightly integrated experience with other Atlassian tools.
  • TeamCity: A commercial CI/CD server from JetBrains, known for its performance and scalability.

Relevant Information

  • Jenkinsfile: Jenkins uses a declarative pipeline syntax defined in a file called Jenkinsfile, which describes the steps and stages of your CI/CD pipeline.
  • Plugins: Jenkins's extensive plugin ecosystem includes plugins for building, testing, deploying, and integrating with various tools like Git, Maven, Gradle, Docker, Kubernetes, and more.
  • Pipeline Stages: A CI/CD pipeline can be divided into stages like build, test, and deploy, each representing a distinct phase of the development process.
  • Parallel Execution: Jenkins can execute multiple tasks in parallel, speeding up the CI/CD process.
  • Blue Ocean: A modern interface for Jenkins that provides a visual representation of your pipelines and makes it easier to interact with them.