Chapter 09Lesson 01~105 minutes

Pipeline Fundamentals, Jenkinsfile, Pipeline Engine, Durable Execution, Nodes, Workspaces, and Stages: Concepts, Architecture, and Mental Model

Build a precise mental model of Jenkins Pipeline: a Jenkinsfile at an exact source revision becomes controller-orchestrated durable program state whose steps acquire agents and workspaces, produce evidence, and persist as one run.

PipelineJenkinsfileCPSNodesWorkspacesDurability

Learning objectives

  • Explain the chain from an exact Jenkinsfile revision to a persisted Pipeline run and stage/step graph.
  • Separate controller-side Pipeline orchestration from agent-side external process execution.
  • Distinguish a node/agent allocation from a workspace and from persisted Pipeline program state.
  • Explain what Pipeline durability can preserve across controller restarts and what it cannot guarantee about external systems.
  • Identify the build number, source SHA, node, workspace, stage/step state, artifacts, and plugin baseline needed for a reproducible evidence chain.

1. The problem: a shell script is not a delivery control plane

A long shell script can compile, test, and deploy software, but by itself it has no Jenkins-aware model of queueing, agents, stage boundaries, approvals, restarts, build history, or retained evidence. Jenkins Pipeline solves a different problem: it lets the controller persist and coordinate a delivery program while individual steps execute where their required resources exist.

That distinction matters during failure. If the controller restarts, Pipeline may resume from persisted program state. If an agent disappears, a node-bound step may need reconnection or reallocation depending on the step and design. If an external deployment API accepted a request before the restart, Jenkins cannot magically reverse that external side effect. Durable orchestration is not transactional rollback.

Chapter 09 rule: always identify three different states: the Pipeline program/run on the controller, the execution context on an agent/workspace, and any external side effect outside Jenkins.

2. Mental model: source → program → allocation → evidence

Start with the Jenkinsfile stored at an exact SCM revision. Jenkins loads that definition for a particular Pipeline build, interprets the Pipeline program, records stage/step progress, requests nodes when steps require executors/workspaces, and keeps a persisted run record under Jenkins controller state.

Pipeline causality — each arrow crosses a distinct state boundary
flowchart TD
  A[Jenkinsfile at exact SCM SHA] --> B[Pipeline job + build number]
  B --> C[Controller Pipeline program / CPS state]
  C --> D[Stage and step graph]
  D --> E{Step needs an agent?}
  E -->|yes| F[Queue + node/label allocation]
  F --> G[Workspace on selected agent]
  G --> H[Durable external process / tool step]
  E -->|no| I[Controller-managed Pipeline step]
  H --> J[Logs / reports / artifact bytes]
  I --> J
  J --> K[Persisted run result + evidence]
  K --> L[External outcome verification]

The controller owns the run identity and orchestration state. The agent owns the process and filesystem context for node-bound work. Artifacts copied into Jenkins or an external repository are a different durability layer from the workspace that produced them.

3. Define the objects before using them

Object Meaning Evidence to keep
Pipeline job The Jenkins item that defines where/how the Pipeline is obtained. Full job name, configuration source, plugin baseline.
Pipeline run One execution with a build number, cause, timestamps, result, and persisted flow graph. Build number/URL, cause, source SHA, final result.
Jenkinsfile Source-controlled Pipeline definition, ideally tied to the same immutable revision as the application. Repository URL/ref and exact Jenkinsfile commit SHA.
Stage A human/visualization boundary grouping related work; not an operating-system process by itself. Stage name, start/end/result, relevant agent.
Step A Pipeline operation implemented by Jenkins core/plugin code, such as echo, sh, archiveArtifacts, or sleep. Step inputs, plugin/provider, logs/results.
Node/agent An execution machine/process registered with Jenkins; a node may expose one or more executors. Node name, labels, executor, Remoting/tool versions.
Workspace A job/build working directory on a selected node. It is operational scratch state, not durable evidence by default. Path, node identity, files promoted out of it.
CPS/program state Persisted/serialized Pipeline continuation state managed by Pipeline plugins on the controller. Installed Pipeline plugin baseline, run identity, restart observations.

4. Groovy orchestration is not “running on the agent”

Pipeline Groovy is interpreted by the Pipeline: Groovy/CPS engine on the controller. A node block or Declarative agent allocates an executor/workspace so specific steps can run remotely. External commands launched by sh, bat, or powershell execute on that agent, not inside the controller JVM.

pipeline {
  agent { label 'lab-linux' }
  stages {
    stage('Observe') {
      steps {
        echo "run=${env.JOB_NAME} #${env.BUILD_NUMBER}"
        sh '''
          set -eu
          printf 'node=%s\nworkspace=%s\n' "$NODE_NAME" "$WORKSPACE"
          uname -a
        '''
      }
    }
  }
}

The echo step and Pipeline program are controller-orchestrated; the shell process runs in the allocated workspace. Keep controller-side Groovy small and orchestration-focused. Heavy CPU/file/network processing belongs in external tools on agents.

5. Durability means persisted continuation, not infinite survivability

Jenkins Pipeline was designed to survive planned and many unplanned controller restarts. Pipeline frequently records execution state to controller storage. Current Jenkins also exposes speed/durability tradeoffs: more aggressive performance settings reduce disk writes but can reduce survivability after abrupt shutdown.

A durable step such as a long-running shell command is implemented so Jenkins can reconnect to or monitor the external process across controller interruptions when the agent/process remains viable. Controller-managed steps such as sleep can also be persisted. But an agent disk loss, deleted workspace, killed external process, revoked credential, or changed external API state is a separate failure domain.

Do not confuse “Pipeline resumed” with “the outside world is unchanged.” After any interruption, verify external side effects before repeating them.

6. Workspace is a lease on scratch state

When Jenkins allocates a node, it chooses a workspace path for the job. That directory may survive between builds on a static agent, may disappear immediately on an ephemeral agent, and may be cleaned by policy. Do not use workspace leftovers as a database or as proof that an artifact was retained.

Need Use Why
Pass small files between stages in the same run stash/unstash when appropriate Moves run-scoped files through Jenkins rather than relying on one workspace.
Retain build evidence after the run archiveArtifacts, reports, or external artifact repository Creates a durable record independent of workspace lifecycle.
Large durable release packages External artifact/package repository Jenkins build archive is not always the right long-term distribution system.

7. agent any, labels, and agent none

A top-level Declarative agent any usually holds one node/workspace across stages. agent none allocates no global agent; each stage that needs a workspace declares its own agent. The second pattern can reduce idle executor consumption around approvals or controller-only coordination, but it also means stages may execute on different machines and therefore cannot assume workspace continuity.

pipeline {
  agent none
  stages {
    stage('Build') {
      agent { label 'linux-builder' }
      steps { sh './build.sh' }
    }
    stage('Approve') {
      steps { input message: 'Promote synthetic build?' }
    }
  }
}

Later chapters go deeper into Declarative syntax. Here the important point is resource ownership: no stage should hold an executor just to wait for a human if it does not need a workspace.

8. Read-only inspection before editing a Pipeline

For an existing build, capture the run URL/number and source revision first. Then inspect stage/step visualization, console log, node/workspace lines, artifacts, and installed Pipeline plugin versions. On an agent, use bounded non-secret commands:

printf 'job=%s\nbuild=%s\nnode=%s\nworkspace=%s\n' \
  "$JOB_NAME" "$BUILD_NUMBER" "$NODE_NAME" "$WORKSPACE"
git rev-parse HEAD
pwd
java -version

Do not dump all environment variables. Pipeline environments often include credentials or provider tokens.

9. Evidence chain for one Pipeline run

Definition

Repository URL/ref, exact Jenkinsfile/source SHA, job full name.

Run

Build number/URL, cause, timestamps, Pipeline plugin baseline.

Execution

Stage/step status, node/label/executor, workspace, tool versions.

Outputs

Reports/artifacts/checksums plus independently verified external state.

10. DevOps connection: durable orchestration is observable state

A production Pipeline should let an operator answer “what definition ran, where did it run, what was persisted, what was merely workspace state, and what side effects happened outside Jenkins?” If those questions cannot be answered after a restart, the automation is not operationally complete.

Next lesson

Guided Hands-On Workflow and Core Operations

Create an SCM-backed Pipeline, inspect its graph and workspace, pause it safely, restart a disposable controller, and prove which run state persists.

Knowledge check

Where does Pipeline Groovy orchestration execute?

Is a workspace a durable artifact store?

What makes a Pipeline run reproducible beyond the Jenkinsfile text?

Does a successful controller restart prove an external deployment step is safe to repeat?

Why might agent none be useful?

Official references and version notes

Version and compatibility note

Rechecked on 2026-09-16. Examples assume Jenkins 2.568.3 LTS, tested with Java 21 and 25. Current reference versions used for compatibility discussion are Pipeline aggregator 608.v67378e9d3db_1, Declarative Pipeline 2.2293.v6e7193cec599, Pipeline: Groovy 4380.v6eb_8378b_9647, Pipeline: Job 1600.v6f36ed83529d, Pipeline: Nodes and Processes 1479.v56e587f413a_7, and optional Pipeline: Stage View 2.41. Plugin releases move independently from Jenkins core; record the installed controller baseline before reproducing a lab. The mandatory exercises use only disposable local resources, no production credentials, and no controller-side untrusted builds.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.