We have a pipeline like this:
pipeline { agent none stages { stage('Build') { // ... } stage('Test') { parallel { stage('Test on Debian') { agent { label 'debian' } steps { unstash 'compile-artifacts' unstash 'dot-gradle' sh './gradlew check --stacktrace' } post { always { junit '*/build/test-results/**/*.xml' } } } stage('Test on CentOS') { agent { label 'centos' } steps { unstash 'compile-artifacts' unstash 'dot-gradle' sh './gradlew check --stacktrace' } post { always { junit '*/build/test-results/**/*.xml' } } } stage('Test on Windows') { agent { label 'windows' } steps { unstash 'compile-artifacts' unstash 'dot-gradle' bat "gradlew.bat check --stacktrace" } post { always { junit '*/build/test-results/**/*.xml' } } } stage('Test on macOS') { agent { label 'macos' } steps { unstash 'compile-artifacts' unstash 'dot-gradle' sh './gradlew check --stacktrace' } post { always { junit '*/build/test-results/**/*.xml' } } } } } } } Every stage is essentially identical, save for one line in the Windows block which I already know how to deal with, so is there a way to template out the common parts of these stages to remove the duplication?
I already tried putting a loop inline, but it's not something that declarative pipelines let you do. :(