Skip to main content

Core Concepts — The Assembly Line Blueprint

Before the factory owner can set up the assembly line, everyone needs to learn the vocabulary. Jenkins has a small set of core concepts — once you understand these, every Jenkins configuration makes sense.

The Big Picture​

Jobs — The Assembly Line Tasks​

A Job (or Project) is a single automated task in Jenkins. It's one assembly line that performs a specific sequence of steps. Jobs are configured, run, and monitored individually.

There are two types:

TypePurposeWhen to use
FreestyleClassic UI-configured jobsSimple, one-off tasks
PipelineCode-defined in a JenkinsfileComplex, version-controlled workflows
Remember

Always prefer Pipeline jobs. The pipeline definition lives in your Git repo (Jenkinsfile), so it's version-controlled and reviewed like any other code.

Pipelines — The Full Assembly Line​

A Pipeline is a sequence of stages that run in order. It's defined in a Jenkinsfile and committed to your repository.

A simple Jenkinsfile
pipeline {
agent any

stages {
stage('Build') {
steps {
sh 'npm install'
sh 'npm run build'
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('Deploy') {
steps {
sh 'docker build -t campus-library .'
sh 'docker push riya/campus-library:latest'
}
}
}
}

Each part explained​

PartMeaningAnalogy
pipelineThe entire workflowThe full assembly line
agentWhere to run (any available machine)Which workstation gets the task
stagesThe major phasesThe assembly line stations
stepsIndividual commands within a stageActions at each station
Remember

A Pipeline is declarative — you describe what happens, and Jenkins figures out how to execute it. This is the recommended syntax.

Stages and Steps — Stations and Actions​

Stages are the major phases of a pipeline (Build, Test, Deploy). Each stage contains one or more steps — individual commands.

Stages with multiple steps
stages {
stage('Build') {
steps {
sh 'echo "Compiling code..."'
sh 'npm run build'
sh 'echo "Build complete!"'
}
}
}

Stages are displayed separately in the Jenkins UI, making it easy to see which phase succeeded or failed.

Agents — The Workstations​

An agent is a machine (physical, virtual, or container) that executes the pipeline. Jenkins can use:

Agent typeDescription
agent anyAny available agent
agent { label 'linux' }An agent with the "linux" label
agent { docker 'node:20' }A fresh Docker container
Docker agent
pipeline {
agent {
docker {
image 'node:20-alpine'
}
}
// ... stages run inside a fresh Node.js container
}
Remember

Docker agents give you a clean environment every time. No leftover files from previous builds. This is the most reliable approach.

Triggers — The Production Schedule​

Triggers define when a pipeline runs automatically:

TriggerPurpose
pollSCMCheck Git periodically for new commits
cronRun on a schedule (e.g., nightly)
upstreamRun when another job completes
WebhookRun instantly when code is pushed (recommended)
SCM polling
triggers {
pollSCM('H/5 * * * *') // Check every 5 minutes
}
Remember

Webhooks are better than polling. Polling checks periodically (wasteful). Webhooks push instantly (efficient). Configure webhooks in your Git provider (GitHub, GitLab).

Shared Libraries — Reusable Factory Parts​

If multiple pipelines repeat the same steps, extract them into a Shared Library:

vars/deployApp.groovy
def call(Map config) {
sh "docker build -t ${config.image} ."
sh "docker push ${config.image}"
sh "kubectl set image deployment/${config.name} web=${config.image}"
}
Use it in a Jenkinsfile
@Library('my-shared-library') _

pipeline {
agent any
stages {
stage('Deploy') {
steps {
deployApp image: 'riya/campus-library:1.0', name: 'campus-library'
}
}
}
}
Remember

Shared libraries are the "reusable jigs" of the factory. Write once, use everywhere.