I would like to be able to easily run the same steps across multiple nodes using the declarative pipeline and a shared library. This does not currently seem to be possible since only custom steps can be created in shared libraries.
Example jenkinsfile:
pipeline {
agent any
stages {
stage('Build everywhere') {
runOnAllPlatforms {
sh 'doing build things'
}
}
}
}
Example shared library vars/runOnAllPlatforms.groovy:
Kevin Lannen I'm getting the following error: ": Starting with version 0.5, steps in a stage must be in a steps block.
Any reason why? I'm reusing your example...
pipeline {
agent any
stages {
stage('Build everywhere') {
runOnAllPlatforms {
sh 'doing build things'
}
}
}
The error is the following:
Branch indexing
Connecting to https://github.intuit.com/api/v3 using mdesales/****** (GitHub Enterprise Access Token)
Obtained Jenkinsfile from 3d42560bb3044468f1acd3c75f1d904e5df15247
Running in Durability level: MAX_SURVIVABILITY
GitHub has been notified of this commit’s build result
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 9: Unknown stage section "runOnAllPlatforms". Starting with version 0.5, steps in a stage must be in a steps block. @ line 9, column 5.
stage('Build everywhere') {
^
WorkflowScript: 9: No "steps" or "parallel" to execute within stage "Build everywhere" @ line 9, column 5.
stage('Build everywhere') {
^
2 errors
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
Yes, there's a very good reason why the code won't work. I wrote that code to demonstrate what how I would like the API to work as a feature request, not as code that currently works hence why this feature request exists.