Jenkins Cheatsheet
Top patterns.
Overview
Jenkins is the long-standing self-hosted CI/CD server that still backs many enterprise pipelines. Five primitives carry most of the operational weight: pipeline-as-code in Jenkinsfile, declarative syntax for most pipelines, plugins for ecosystem coverage, distributed builds across agents, and shared libraries for DRY Groovy code. Self-hosted control matters where compliance or air-gap requirements rule out hosted CI.
- Pipeline-as-code.
Jenkinsfilein the repo defines the pipeline. Version-controlled CI from day one. - Declarative and scripted syntax. Two pipeline styles. Prefer declarative for most cases; scripted for genuine flexibility needs.
- Plugins. Vast ecosystem. Manage versions deliberately to avoid surprise breakage.
- Distributed builds plus shared libraries. Master orchestrates agents for build volume; shared libraries supply reusable Groovy across pipelines.
The approach
Five idioms cover most operational Jenkins use. Memorising them turns Jenkinsfile authoring from copy-paste exercises into reviewable pipeline design.
- Declarative skeleton.
pipeline { agent any; stages { stage('Build') { steps { sh 'make' } } } }. The starting point for most pipelines. - Branch-specific stages.
when { branch 'main' }. Selective execution per branch. - Concurrent stages.
parallel { ... }. Cuts feedback time on independent work. - Post-lifecycle hooks plus shared libraries.
post { always { ... } failure { ... } }for cleanup;library('shared@main')for DRY pipelines.
Why this compounds
Each pipeline captures testing knowledge in a reviewable artefact. Shared libraries spread patterns across the org; pinned plugins keep the platform stable; self-hosted control satisfies the compliance requirements that hosted CI cannot.
- Reusable pipelines. Shared libraries scale with org size. Pipelines stay consistent across teams.
- Operational control. Self-hosted Jenkins keeps CI in the team’s environment. Compliance frameworks like that.
- Plugin discipline. Pinned plugins reduce surprise breakage. The platform stays stable.
- Year-one investment, year-two habit. First year builds the patterns. By year two, every new repo ships with a Jenkinsfile that fits the conventions.