Course contentsShow
← Cloud and Infrastructure
Lesson 1784 of 2,98937. JenkinsFree lesson

Pipeline Structure and Anatomy

Learn the basic structure of a Declarative pipeline with pipeline, agent, and stages blocks.

Pipeline Structure and Anatomy

You'll learn: The fundamental building blocks of a Declarative Jenkins pipeline and how they fit together.

Core Structure of Declarative Pipelines

A Declarative pipeline in Jenkins follows a structured template that organizes your CI/CD logic into distinct sections. Think of it like constructing a building: you need a foundation (pipeline), a location to build (agent), and floors with rooms (stages and steps).

The Three Essential Blocks

pipeline

The outermost container that defines the entire pipeline. Everything must be enclosed within this block—it's the foundation of your pipeline structure.

agent

Specifies where your pipeline executes. You can define it at the top level (applies to all stages) or per-stage. Common values include any (use any available agent) or specific labels for targeted execution.

stages

Contains one or more stage blocks that logically group your pipeline work. Each stage represents a phase like "Build," "Test," or "Deploy." Stages execute sequentially by default and provide clear visualization in Jenkins UI.

Basic Structure Example

pipeline {
    agent any
    
    stages {
        stage('Build') {
            steps {
                echo 'Building application...'
            }
        }
        stage('Test') {
            steps {
                echo 'Running tests...'
            }
        }
    }
}

This anatomy creates a predictable, readable structure where each section has a clear purpose: pipeline declares the start, agent picks the executor, and stages organize your workflow into logical phases.

Key Takeaway: Declarative pipelines require three nested blocks—pipeline wraps everything, agent defines where to run, and stages organizes your build phases into a clear, sequential structure.