Skip to main content
In this guide, you’ll learn how to convert a Declarative Pipeline into a fully Scripted Pipeline for the solar-system repository on the features/advanced-demo branch. We’ll cover tool setup, environment configuration, caching, timestamps, and concurrency control.

1. Review the Existing Declarative Pipeline

The current pipeline installs Node.js, sets environment variables, and caches npm dependencies:

2. Create and Push the Scripted Branch

Pushing this branch triggers a new build in Jenkins.
The image shows a Jenkins dashboard for a project named "solar-system," displaying the status of various branches with details on their last success, last failure, and duration.

3. Define the Scripted Pipeline

Wrap all steps inside a node block and configure tools, environment, and build properties:
Caching node_modules speeds up CI by restoring dependencies from the cache on subsequent runs, reducing network overhead.

4. Check Pipeline Syntax Reference

If you need to explore other Scripted Pipeline constructs, consult the official syntax guide.
The image shows a webpage from the Jenkins documentation, specifically detailing pipeline syntax options. It includes a sidebar with navigation links and a main section describing various options like disableConcurrentBuilds and disableResume.

5. Validate First and Subsequent Runs

On the first run, the cache is empty:
On subsequent runs, the cache is restored for faster installs:

6. Ensure Concurrency Control

Start two builds in quick succession; the earlier build will be aborted to honor abortPrevious: true.
The image shows a Jenkins pipeline interface with build history and stages for a project named "solar-system." It displays the status of three builds, including their start, checkout, and end stages.
Aborting previous builds can interrupt cleanup tasks. Ensure your pipeline handles partial states and rollbacks correctly.

Table: Key Pipeline Options

Watch Video