Declarative Pipelines are the newest additions to Jenkins that simplify the groovy syntax of Jenkins pipelines (top-level pipeline) with some exceptions, such as:
No semicolon to be used as a statement separator. The top-level pipeline should be enclosed within block viz;
The common syntax is:
pipeline {
/* Declarative Pipeline */
}
Blocks must contain Sections, Directives, steps or assignments.
pipeline {
agent any
stages {
stage(‘Build’) {
steps {
// Statements…
}
}
stage (‘Test’) {
steps {
// Statements…
}
}
}
}
The above code has 3 major elements
Pipeline: The block of script contents.
Agent: Defines where the pipeline will start running from.
Stage: The pipelines contain several steps enclosed in the block called Stage.