0
0
Jenkinsdevops~10 mins

Declarative pipeline syntax in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Declarative pipeline syntax
Start pipeline
Define pipeline block
Specify agent
Define stages
Stage 1: Steps
Stage 2: Steps
Post actions (optional)
Pipeline ends
The declarative pipeline starts with a pipeline block, specifies an agent, defines stages with steps, and optionally post actions before ending.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
}
This pipeline runs on any agent and has one stage 'Build' that prints 'Building...'.
Process Table
StepActionEvaluationResult
1Start pipelinepipeline block foundPipeline execution begins
2Agent specifiedagent anyRuns on any available agent
3Enter stages blockstages foundPrepare to run stages
4Enter stage 'Build'stage('Build') foundReady to run Build stage
5Execute steps in 'Build'steps { echo 'Building...' }Prints 'Building...' to console
6No more stagesend of stagesStages complete
7No post actionspost block missingPipeline ends
8Pipeline endsend of pipeline blockPipeline execution finished
💡 Pipeline completes after all stages and steps run successfully.
Status Tracker
VariableStartAfter Step 2After Step 5Final
pipelineundefineddefineddefineddefined
agentundefinedanyanyany
stagesundefineddefineddefineddefined
stage 'Build'undefinedundefinedexecutingexecuted
Key Moments - 3 Insights
Why do we need to specify an agent in the pipeline?
The agent tells Jenkins where to run the pipeline. Without it, Jenkins doesn't know which machine or environment to use. See step 2 in the execution table where 'agent any' means it can run anywhere.
What happens if we forget to put steps inside a stage?
Stages need steps to do work. Without steps, the stage runs but does nothing. In the execution table, step 5 shows the steps block running the echo command. Without it, no action happens.
Can the pipeline run without stages?
No, stages organize the pipeline work. The pipeline block requires stages to define tasks. Step 3 shows entering stages block; without it, the pipeline has no tasks to run.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the agent value after step 2?
Anone
Bany
Cundefined
Dagent not set
💡 Hint
Check the 'agent' row in variable_tracker after Step 2.
At which step does the pipeline print 'Building...'?
AStep 4
BStep 6
CStep 5
DStep 3
💡 Hint
Look at the 'Execute steps in Build' action in the execution_table.
If we add a post block, at which step would it execute?
AAfter Step 6
BBefore Step 4
CAfter Step 7
DAt Step 2
💡 Hint
Post actions run after all stages complete, see step 6 and 7 in execution_table.
Concept Snapshot
Declarative pipeline syntax:
pipeline {
  agent any
  stages {
    stage('Name') {
      steps { ... }
    }
  }
  post { ... }
}
- agent defines where to run
- stages contain ordered tasks
- steps are commands inside stages
- post runs after stages finish
Full Transcript
The declarative pipeline in Jenkins starts with a pipeline block that defines the whole process. Inside, an agent is specified to tell Jenkins where to run the pipeline. Then stages are defined, each with a name and steps that perform actions. For example, a 'Build' stage can have steps that print messages or run commands. After all stages run, optional post actions can execute for cleanup or notifications. The pipeline ends after all these steps complete. This flow ensures Jenkins knows what to do, where, and in what order.