How to Install and Configure Jenkins on Your VPS
Jenkins is a popular automation server that helps streamline development workflows by automating tasks like building, testing, and deploying applications. Setting it up on your VPS can significantly enhance your development process.
Step 1: Update Your System
Start by updating your VPS to ensure all packages and dependencies are up-to-date.
- Update the package lists and upgrade installed packages:
sudo apt update && sudo apt upgrade -y
Step 2: Install Java
Jenkins requires Java to run. Install the necessary version of Java.
- Install OpenJDK:
sudo apt install openjdk-11-jdk -y
- Verify the Java installation:
You should see output indicating the installed version of Java.java -version
Step 3: Add the Jenkins Repository
To ensure you get the latest version of Jenkins, add the official Jenkins repository to your system.
- Import the GPG key for the Jenkins repository:
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc
- Add the Jenkins repository to your system:
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
- Update your package lists:
sudo apt update
Step 4: Install Jenkins
Once the repository is added, install Jenkins.
- Run the following command:
sudo apt install jenkins -y
- Verify the installation:
dpkg -l | grep jenkins
Step 5: Start and Enable the Jenkins Service
Ensure Jenkins starts automatically and is running.
- Start the Jenkins service:
sudo systemctl start jenkins
- Enable Jenkins to start on boot:
sudo systemctl enable jenkins
- Check the status of the service:
sudo systemctl status jenkins
Step 6: Adjust Firewall Settings
If you have a firewall enabled, allow Jenkins to be accessible.
- Allow Jenkins default port (8080):
sudo ufw allow 8080
- Reload the firewall rules:
sudo ufw reload
Step 7: Access Jenkins via Web Browser
You can now access Jenkins through your web browser.
- Open your browser and navigate to:
Replacehttp://<your-vps-ip>:8080
<your-vps-ip>
with the IP address of your VPS.
Step 8: Unlock Jenkins
The first time you access Jenkins, it will ask for an administrator password.
- Retrieve the password by running:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Copy the password and paste it into the Jenkins web interface.
Step 9: Install Suggested Plugins
After unlocking Jenkins, it will prompt you to install plugins.
- Choose the option to install suggested plugins for a quick setup.
- Wait for the installation to complete.
Step 10: Create an Admin User
Once the plugins are installed, Jenkins will prompt you to create an admin user.
- Fill in the required details (username, password, full name, and email).
- Save the information to proceed.
Step 11: Configure Jenkins for Your Needs
You can now start configuring Jenkins to automate your development tasks.
- Set up your first job by clicking on "New Item" in the Jenkins dashboard.
- Explore available plugins to integrate Jenkins with your version control system, build tools, and deployment platforms.
Step 12: Secure Your Jenkins Installation
To enhance security, consider the following:
- Change the default port by editing the Jenkins configuration file:
Update the linesudo nano /etc/default/jenkins
HTTP_PORT=8080
to your desired port, save the file, and restart Jenkins:sudo systemctl restart jenkins
- Use HTTPS by configuring Jenkins with an SSL certificate.
Step 13: Test Your Jenkins Setup
Run a test job to ensure Jenkins is functioning properly.
- Create a simple "Hello World" pipeline or freestyle job.
- Run the job and confirm successful execution in the Jenkins dashboard.
Conclusion
Jenkins is now installed and ready to automate your workflows. By following these steps, you’ve set up a powerful tool to streamline development, testing, and deployment processes on your VPS. Remember to keep Jenkins and its plugins updated to maintain security and functionality.