Configuring advanced Scripted Pipeline

1 minute read

Scripted Pipeline is a domain-specific language based on Groovy, most Groovy syntax can be used in Scripted Pipeline without modification.

Executing in parallel

The example below runs tests across two different platforms in a linear series. In practice, if the make check execution takes 30 minutes to complete, the "Test" stage would now take 60 minutes to complete!

Fortunately, Pipeline has built-in functionality for executing portions of Scripted Pipeline in parallel, implemented in the aptly named parallel step.

Declarative syntax
Scripted syntax
pipeline { agent none stages { stage('Build') { /* .. snip ..*/ } stage('Test') { parallel { stage('linux') { agent { label 'windows' } steps { unstash 'app' sh 'make check' junit '**/target/*.xml' } } stage('windows') { agent { label 'windows' } steps { /* ... snip .. */ } } } } } }
stage('Build') { /* .. snip .. */ } stage('Test') { parallel linux: { node('linux') { checkout scm try { unstash 'app' sh 'make check' } finally { junit '**/target/*.xml' } } }, windows: { node('windows') { /* .. snip .. */ } } }

Instead of executing the tests on the "linux" and "windows" labelled nodes in series, they will now execute in parallel assuming the requisite capacity exists in the Jenkins environment.