Problem Statement
What is the root element of a Declarative Pipeline?
Explanation
Declarative Pipeline always starts with a pipeline block as the root element. This block contains all pipeline configuration including agent, stages, post actions, and other directives. The pipeline block is mandatory and defines the entire pipeline structure using a predefined, opinionated syntax that's easier to read and write than Scripted Pipeline.
Inside the pipeline block, you define key sections: agent (where to run), stages (pipeline phases), post (post-build actions), environment (environment variables), options (pipeline-level settings), parameters (build parameters), and triggers (build triggers). Example:
```groovy
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'make'
}
}
}
}
```
The pipeline block enforces structure making pipelines more consistent and maintainable. In contrast, Scripted Pipeline uses node block as the root and allows arbitrary Groovy code. Understanding the pipeline block structure is fundamental to writing Declarative Pipelines correctly.
