Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Using Jenkins - Comprehensive Tutorial

Introduction

Jenkins is an open-source automation server that enables developers to build, test, and deploy their software reliably. This tutorial will guide you through the process of setting up Jenkins on a Linux server and using it to automate software development workflows.

Installation

To install Jenkins on a Linux server, follow these steps:

1. Update your system packages:

sudo apt-get update
                    ...
                    

2. Install Java (Jenkins requires Java to run):

sudo apt-get install openjdk-11-jdk
                    ...
                    

3. Add the Jenkins repository:

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
                    ...
                    

4. Install Jenkins:

sudo apt-get update
sudo apt-get install jenkins
                    ...
                    

5. Start Jenkins and enable it to start at boot:

sudo systemctl start jenkins
sudo systemctl enable jenkins
                    ...
                    

Setting Up Jenkins

Once Jenkins is installed, you can access its web interface and complete the setup.

1. Open a web browser and navigate to:

http://your_server_ip_or_domain:8080

2. You will be prompted to unlock Jenkins. Retrieve the initial admin password:

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

3. Enter the password in the web interface and follow the on-screen instructions to complete the setup.

Creating Your First Job

Let's create a simple job in Jenkins that builds a project.

1. Click on "New Item" in the Jenkins dashboard.

2. Enter a name for your job, select "Freestyle project," and click "OK."

3. In the configuration page, scroll down to the "Build" section and click "Add build step."

4. Choose "Execute shell" and enter the shell commands to build your project. For example:

echo "Building the project..."
make

5. Click "Save" to create the job.

6. To run the job, click "Build Now" in the job's dashboard.

Configuring Jenkins with Plugins

Jenkins has a rich ecosystem of plugins that extend its functionality. Here's how to manage plugins:

1. Go to "Manage Jenkins" -> "Manage Plugins."

2. In the "Available" tab, you can search for and install new plugins. For example, search for "Git" and install the Git plugin.

3. After the plugin is installed, you might need to restart Jenkins.

4. To check installed plugins, go to the "Installed" tab.

Setting Up Continuous Integration

Continuous Integration (CI) is a key practice in DevOps. Here's how to set up a CI pipeline with Jenkins:

1. Create a new job as described earlier.

2. In the "Source Code Management" section, select "Git" and enter your repository URL.

3. In the "Build Triggers" section, select "Poll SCM" and set the polling schedule. For example, to poll every 15 minutes:

H/15 * * * *

4. Add build steps as needed (e.g., compile, test, package).

5. Save the job and test it by committing changes to your repository.

Monitoring Jenkins

Monitoring Jenkins is crucial to ensure that it is running smoothly.

1. Go to "Manage Jenkins" -> "System Log" to view the system logs.

2. You can also install monitoring plugins like "Monitoring" to get detailed metrics.

Conclusion

Jenkins is a powerful tool for automating software development workflows. By following this tutorial, you should have a good understanding of how to set up and use Jenkins for your projects.