DevOps / CI/CD (Continuous Integration and Continuous Deployment)

Configuring Jenkins for CI/CD

This tutorial will guide you through the process of setting up Jenkins, a popular open-source tool used for continuous integration and delivery. You will learn how to configure Je…

Tutorial 3 of 5 5 resources in this section

Section overview

5 resources

Covers automating software delivery pipelines to enable continuous integration and continuous deployment.

1. Introduction

In this tutorial, our main goal is to configure Jenkins for Continuous Integration/Continuous Delivery (CI/CD). Jenkins is an open-source automation server that allows you to automate different stages of your delivery pipeline. You will learn how to set up Jenkins, create a simple pipeline, and integrate it with a version control system.

You will learn how to:
- Install Jenkins
- Configure Jenkins
- Create a Jenkins pipeline
- Integrate Jenkins with GitHub

Prerequisites:
- Basic knowledge of version control systems, preferably Git
- Java installed on your system
- A GitHub account

2. Step-by-Step Guide

2.1 Installing Jenkins

First, you need to install Jenkins. Here are the steps to install Jenkins on Ubuntu:

  1. Update your system with sudo apt update
  2. Install Java Development Kit with sudo apt install openjdk-11-jdk
  3. Add the Jenkins Debian repository with wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
  4. Append the Debian package repository address to the server's sources.list: echo deb http://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list
  5. Update the apt package list and install Jenkins sudo apt update && sudo apt install jenkins

After installation, Jenkins service will start automatically. You can check its status using systemctl status jenkins

2.2 Configuring Jenkins

Open your web browser and navigate to http://localhost:8080. You'll see a Unlock Jenkins page. To find the password, use the command sudo cat /var/lib/jenkins/secrets/initialAdminPassword. Copy the password, paste it into the form, and click Continue.

Next, you'll be prompted to customize Jenkins. For this tutorial, select Install suggested plugins. Jenkins will then install the suggested plugins.

2.3 Creating a Jenkins Pipeline

Once Jenkins is configured, you need to create a new job. On the Jenkins dashboard, click on New Item. In the next screen, enter a name for the job, select Pipeline, and click OK.

In the pipeline configuration page, scroll down to the Pipeline section. Here, you can define your pipeline script. For simplicity, we'll create a pipeline that prints a simple message.

pipeline {
    agent any

    stages {
        stage('Stage 1') {
            steps {
                echo 'Hello, Jenkins!'
            }
        }
    }
}

Click Save to finish creating the pipeline.

2.4 Integrating Jenkins with GitHub

To integrate Jenkins with GitHub, you need to install the GitHub plugin. Go to Manage Jenkins > Manage Plugins > Available, then find and select GitHub plugin. Click on Install without restart.

After installing the plugin, go to your job configuration page and in the Pipeline section, select Pipeline script from SCM. Then, select Git and enter your repository URL.

3. Code Examples

Here's an example of a Jenkins pipeline that clones a Git repository and builds a Java project with Maven. The example assumes you have a Maven project in your repository.

pipeline {
    agent any

    stages {
        stage('Clone repository') {
            steps {
                git 'https://github.com/your-repository.git'
            }
        }

        stage('Build') {
            steps {
                sh 'mvn clean install'
            }
        }
    }
}

4. Summary

In this tutorial, you've learned how to install and configure Jenkins, create a simple pipeline, and integrate Jenkins with GitHub. To expand your knowledge, you can explore how to use Jenkins with other version control systems, and how to configure complex pipelines.

5. Practice Exercises

Exercise 1: Install Jenkins on your local machine and create a simple pipeline that prints a message.

Exercise 2: Create a Jenkins pipeline that clones a Git repository and lists the files in the repository.

Exercise 3: Create a Jenkins pipeline that clones a Git repository, builds a Java project with Maven, and archives the build results.

Remember, practice is the key to mastering any skill. Keep experimenting with different pipeline configurations and Jenkins features.

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Color Palette Generator

Generate color palettes from images.

Use tool

AES Encryption/Decryption

Encrypt and decrypt text using AES encryption.

Use tool

PDF Splitter & Merger

Split, merge, or rearrange PDF files.

Use tool

Random String Generator

Generate random alphanumeric strings for API keys or unique IDs.

Use tool

Open Graph Preview Tool

Preview and test Open Graph meta tags for social media.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help