TechyPilots Info
TechyPilots.INFO
CI/CD Automation Tutorial

Jenkins

Learn how Jenkins automates software builds, testing, integration, delivery, and deployment using pipelines, Jenkinsfiles, stages, agents, and plugins.

Level: Beginner to Intermediate
Topic: CI/CD Automation

Jenkins Pipeline

Automate Your Software Delivery

Source Code

Build Application

Run Tests

Package Application

Deploy Application

Introduction

What is Jenkins?

Jenkins is an automation platform commonly used to build Continuous Integration and Continuous Delivery pipelines.

Jenkins Pipelines allow teams to define software delivery workflows as code. A Pipeline can include stages for building, testing, packaging, and deploying applications.

Pipelines are commonly stored in a file called aJenkinsfile, allowing the automation process to be versioned alongside the application source code.

Core Concepts

Understanding Jenkins

Jenkins Pipelines combine stages, steps, agents, source control, and plugins to automate different parts of the software delivery lifecycle.

01

Jenkins Pipeline

A Jenkins Pipeline defines an automated software delivery process. It can model stages such as building, testing, packaging, and deployment.

Key Topics

  • Pipeline as Code
  • Continuous Integration
  • Continuous Delivery
  • Automation workflows
02

Jenkinsfile

A Jenkinsfile contains the definition of a Jenkins Pipeline and can be stored in source control alongside the application code.

Key Topics

  • Source control
  • Pipeline configuration
  • Version control
  • Automation code
03

Stages

Stages organize a Pipeline into logical phases such as Build, Test, Security Scan, Package, and Deploy.

Key Topics

  • Build
  • Test
  • Package
  • Deploy
04

Steps

Steps are individual tasks that Jenkins executes inside a stage, such as running shell commands, tests, or other automation actions.

Key Topics

  • Shell commands
  • Build commands
  • Testing
  • Automation tasks

Jenkins Architecture

Main components of Jenkins

Controller

The Jenkins controller manages the Jenkins environment, coordinates jobs, and schedules Pipeline execution.

Agent

An agent provides an execution environment where Jenkins jobs and Pipeline stages can run.

Pipeline

A Pipeline defines the complete automation process used to build, test, and deliver software.

Stage

A logical section of a Pipeline representing a specific phase of the delivery process.

Step

An individual operation that Jenkins performs as part of a Pipeline.

Plugin

Plugins extend Jenkins with integrations, build tools, source control support, notifications, cloud platforms, and additional functionality.

Pipeline as Code

What is a Jenkinsfile?

A Jenkinsfile is a text file containing the definition of a Jenkins Pipeline. It can be committed to the same source control repository as your application.

This approach allows your CI/CD workflow to be reviewed, versioned, updated, and maintained as part of the software project.

Jenkins supports both Declarative Pipeline and Scripted Pipeline syntax. Declarative syntax provides a structured approach, while Scripted Pipeline offers more flexibility for advanced use cases.

Example Project Structure

my-project/
│
├── src/
│
├── package.json
│
├── README.md
│
└── Jenkinsfile

Your First Pipeline

Create a basic Jenkins Pipeline

This example shows a simple Declarative Pipeline with stages for checking out source code, building the application, running tests, and preparing for deployment.

Each stage contains one or more steps that Jenkins executes on the configured agent.

Jenkinsfile

pipeline {
    agent any

    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }

        stage('Build') {
            steps {
                sh 'npm ci'
                sh 'npm run build'
            }
        }

        stage('Test') {
            steps {
                sh 'npm test'
            }
        }

        stage('Deploy') {
            steps {
                echo 'Deploying application'
            }
        }
    }
}

Pipeline Execution

How a Jenkins Pipeline works

01

Code Change

A developer pushes code or creates a change in the source control repository.

02

Pipeline Trigger

Jenkins starts the configured job or Pipeline based on a trigger or manual action.

03

Agent Allocated

Jenkins allocates an available execution environment for the Pipeline or stage.

04

Build and Test

The Pipeline runs build commands, tests, validation, and other automation tasks.

05

Package Application

A successful build can create artifacts, packages, or container images.

06

Deploy Application

The final Pipeline stages can deploy the validated application to the required environment.

Use Cases

What can Jenkins automate?

Jenkins can automate many tasks throughout the software development and delivery lifecycle.

Continuous Integration

Automatically build and test software changes whenever developers push code to a repository.

Continuous Delivery

Automate the software delivery process and prepare validated application builds for deployment.

Application Testing

Run automated unit tests, integration tests, and other validation processes as part of a Pipeline.

Docker Automation

Build container images and integrate container workflows into your CI/CD pipeline.

Cloud Deployments

Automate deployments to cloud infrastructure, virtual machines, Kubernetes environments, or other platforms.

Scheduled Automation

Run recurring jobs for backups, maintenance, reports, monitoring, or other scheduled tasks.

Learning Roadmap

How to learn Jenkins

Follow these steps to move from Jenkins fundamentals to building complete CI/CD pipelines.

Step 1

Understand Jenkins Basics

Learn how Jenkins is used for automation and understand the role of controllers, agents, jobs, and plugins.

Step 2

Create Your First Job

Create a simple Jenkins job and run basic build or automation commands.

Step 3

Learn Jenkins Pipelines

Understand Pipeline syntax and how stages and steps define an automated workflow.

Step 4

Create a Jenkinsfile

Define your Pipeline in a Jenkinsfile and store it in your application's source code repository.

Step 5

Add Testing and Builds

Automate dependency installation, application builds, tests, linting, and other validation processes.

Step 6

Build a Complete CI/CD Pipeline

Combine source control, builds, tests, containerization, and deployment into a complete automated delivery pipeline.

Best Practices

Jenkins best practices

Use Jenkinsfile

Store Pipeline definitions in source control so CI/CD workflows can be versioned and reviewed with the application code.

Keep Pipelines Clear

Use descriptive names for stages and organize automation into logical parts of the delivery process.

Use Secure Credentials

Store passwords, tokens, keys, and other sensitive values using Jenkins credential management instead of hardcoding them.

Separate Build Stages

Keep build, test, security, packaging, and deployment processes separated for easier troubleshooting.

Use Agents Efficiently

Configure appropriate agents and execution environments for different workloads and Pipeline stages.

Monitor Pipeline Results

Review build logs, test results, failures, and Pipeline execution history to identify issues quickly.

Next Step

Start building Jenkins Pipelines

Practice creating Jenkinsfiles, defining stages, running builds, executing tests, using agents, and building complete CI/CD automation workflows.