Pipeline project types

2 minute read

The following Pipeline project types are available:

Declarative Pipeline

A declarative Pipeline provides a structured hierarchical syntax to simplify the creation of Pipelines and the associated Jenkinsfiles. It is newer than scripted Pipeline. In its simplest form, a Pipeline runs on an agent and contains stages, while each stage contains steps that define specific actions. Here is an example:

pipeline { agent { (1) label '' } stages { stage(‘Build’) { (2) steps { (3) sh ‘mvn install’ } } } }
1 agent - An agent section specifies where tasks in a Pipeline run. An agent must be defined at the top level inside the pipeline block to define the default agent for all stages in the Pipeline. An agent section may optionally be specified at the stage level, overriding the default for this stage and any child stages. In this example, the agent is specified with an empty label filter, meaning this Pipeline will run on any available agent.

The code snippet above does not show an agent running on Kubernetes. An agent running on Kubernetes is configured differently.

2 stages - A stage represents a logical grouping of tasks in the Pipeline. Each stage may contain a steps section with steps to be executed, or stages to be executed sequentially, in parallel, or expanded into a parallel matrix.

It contains commands that run processes like Build, Deploy, or Tests. These commands are included in the steps section in the stage.

It is advisible to have descriptive names for a stage as these names are displayed in the UI and logs.

There can be one or more stage sections inside a stages section. At least one stage must be defined in the stages section.

3 steps - The `steps`section contains a set of commands. Each command performs a specific action and is executed one-by-one.
pipeline { agent any stages { stage('Example') { steps { sh 'mvn compile' } } } }

For more information on Declarative Pipelines, see Using Declarative Pipeline syntax.

Scripted Pipeline

Scripted Pipeline is a Domain Specific Language (DSL) based on Apache Groovy. Most functionality provided by the Groovy language is made available in Scripted Pipelines. This means Scripted Pipelines can offer flexibility and extensibility to users.

However, the learning curve associated with Scripted Pipelines is very steep and it is possible to do things inside Pipelines that are better done in other tools called as part of Pipelines. CloudBees recommends the use of Declarative Pipelines rather than Scripted Pipelines.

For more information on Scripted Pipelines, see Using Scripted Pipeline syntax.

Freestyle projects

Freestyle projects are used to implement, develop, or run simple jobs. They can span multiple operations like building and running scripts.

CloudBees recommends the use of Pipeline projects instead of Freestyle projects. For information about converting a Freestyle project to a Declarative Pipeline please see Converting a Freestyle project to a Declarative Pipeline.

Multibranch Pipelines

A multibranch Pipeline can be used to automatically create Pipelines based on branches and pull requests in your repository. For more information on multi-branch Pipelines, see Managing Multibranch Pipeline options in template.yaml.