- Run a single stage: Installing Dependencies
- Enable timestamper output
- Disable concurrent builds (abort previous runs)
- Use the NodeJS tool configured in Jenkins
- Reuse the existing cache logic
- Working repo:
solar-system - Current branch:
feature/advanced-demo

- Declarative pipelines use a top-level
pipeline { ... }block and many built-in directives. - Scripted pipelines run inside
node { ... }and require some Declarative-only features (for exampleoptions { ... }) to be expressed withproperties(...)or appropriate wrappers.
Scripted pipelines always run inside
node { ... }. Declarative-only directives (like options) must be converted to properties(...) or equivalent build wrappers when migrating to Scripted pipelines.
Converting NodeJS tool usage
- Declarative pipelines commonly declare tools via
tools { nodejs 'name' }. - In Scripted pipelines, resolve the tool with
tool(...), then export it toenvand updatePATHsonode/npmbecome available.
- Declarative
optionslikedisableConcurrentBuilds(abortPrevious: true)must be applied viaproperties(...)in Scripted pipelines. - Call
properties(...)once inside yournodeblock (typically near the start of the Jenkinsfile).
- To enable timestamped console output in Scripted pipelines, use the
wrapstep with the Timestamper build wrapper:
env.NODEJS_HOME = "${tool 'nodejs-22-6-0'}"resolves the NodeJS installation by name and updatesPATHsonodeandnpmare available.properties([...])is the Scripted equivalent for certain Declarativeoptions(in this example,disableConcurrentBuilds(abortPrevious: true)).wrap([$class: 'TimestamperBuildWrapper'])enables timestamps for the wrapped stage(s).- The
cache { ... }block mirrors Declarative cache-plugin usage; adjustfiles/cacheNameper your cache plugin configuration.
- Checkout phase (shortened):
- Cache restore/create messages:
disableConcurrentBuilds(abortPrevious: true)
- When multiple builds for the same branch are triggered, earlier running builds will be interrupted and marked as superseded; the latest build proceeds. Console output may include:
- Wrap your pipeline steps in
node { ... }. - Resolve global tools via
tool(...)and export toenv. - Convert Declarative
optionsusingproperties([ ... ]). - Use
wrap([$class: 'TimestamperBuildWrapper'])to get timestamped logs. - Keep existing cache and shell steps unchanged inside the Scripted flow.
- Jenkins Pipeline Syntax
- Timestamper Plugin
- Jenkins Tools Configuration
- Jenkins Pipeline: properties step