Jenkins Pipeline Generator

Generate production-ready Jenkinsfiles using modern Declarative Pipeline syntax or advanced Scripted Pipeline.

Jenkins Pipeline

Pipeline Options

Pipeline Stages

Post-build Actions

Jenkinsfile
1

How to Write a Jenkinsfile

What is a Jenkinsfile?

A Jenkinsfile is a text file that contains the definition of a Jenkins Pipeline and is checked into source control. It allows you to model your deployment pipeline as code (Pipeline-as-Code).

Declarative vs. Scripted Pipeline

Jenkins supports two different syntax paradigms:

#

  • Declarative Pipeline (Recommended)
  • Declarative Pipeline is a more recent and advanced addition to Jenkins. It provides a more structured, simpler, and highly opinionated syntax. It enforces a strict block structure (e.g., pipeline, agent, stages, steps, post).

  • Best for: Most standard CI/CD use cases, beginners, and ensuring enterprise standardization.
  • Validation: Easier to validate and catch errors before execution.
  • #

  • Scripted Pipeline
  • Scripted Pipeline is the traditional way to write Jenkinsfiles. It is essentially a full-fledged Groovy script executed inside Jenkins.

  • Best for: Complex pipelines with dynamic behavior, loops, conditional logic, and heavy use of custom shared libraries.
  • Structure: Less structured, starts with a node block.
  • Key Concepts

  • Agent: Defines where the entire pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent directive is placed.
  • Stages/Steps: A stage block defines a conceptually distinct subset of tasks performed through the entire pipeline (e.g. "Build", "Test", "Deploy"). A step is a single task.
  • Post: The post section defines actions that will run at the end of the pipeline or a stage. Common use cases include sending notifications or cleaning up the workspace.