Jenkins Declarative Pipeline Essentials

Brian Grogan Jr.
Qualitas Ex Machina
2 min readMay 26, 2022
Photo by Sigmund on Unsplash

When the declarative pipeline syntax for Jenkins was released, I was very excited. A declarative, low-code syntax for CI pipeline configurations makes a ton of sense. I was ready to dive into declarative world, head-first.

I’ve been configuring Jenkins pipelines with several projects in the declarative style for a few years now. The syntax is definitely cleaner and much improved, but one thing that still hasn’t really improved is the documentation for the declarative syntax. The declarative syntax has been available for over 5 years now, and I’m still finding documents and tutorials written as if everyone is still writing Scripted Groovy pipelines.

Here are a few essential concepts for declarative pipelines. I’ll go into more details in further posts. In some small way, maybe this can help clear some things up:

Pipeline Root Element

// Jenkinsfilepipeline {  // ... stages, options, and other things go here}

Declarative pipelines begin with the pipeline element. The pipeline element is the root element of the Jenkinsfile. All the stages, options, and other pieces of the pipeline go inside the pipeline element, between the braces: {}

Agent Section

pipeline {  agent any  // any available agent machine}

Every pipeline must run somewhere, and you specify the machine running the pipeline with the agent section. The most common option is any, but you can also provide selector expressions to pick specific machines, if needed.

Stages Section

pipeline {
agent any
stages {
// ... pipeline stages go here
}
}

Every pipeline must contain 1 or more stages, and you define each stage in the stages section.

More to come …

So those elements are the absolute essentials of Jenkins declarative pipelines. They are required in every pipeline you write. Next up, I’ll go into some details for specifying agent machines.

--

--

Brian Grogan Jr.
Qualitas Ex Machina

Software Quality Engineer fighting for truth, justice, and better quality apps. Thinks a lot about Automation and CI/CD, in both practical and abstract terms.