Generate pipeline parallel steps

163 views
Skip to first unread message

Tomas Pekarovic

unread,
Mar 22, 2017, 7:30:40 AM3/22/17
to Jenkins Users
Hi all,

 I'm trying to change my multiconfiguration project into pipeline. I need to generate parallel steps and than run it.

Can somebody try to help me what am I doing wrong? I just cant figure it out.

====codes===

=============== pipeline =========
def run = [:]
for (int i = 0; i <= 5; i++) {
  println "adding $i"
  def currentRun = {
node('master') {
bat 'echo "hello $i"'
    }
  }
  run.put("\"test $i\"", currentRun)
}


pipeline {
    agent none
    stages {
        stage('new'){
            steps {
                echo "${run}"
            }
        }
}
}
========== output ======================
[Pipeline] echo
adding 0
[Pipeline] echo
adding 1
[Pipeline] echo
adding 2
[Pipeline] echo
adding 3
[Pipeline] echo
adding 4
[Pipeline] echo
adding 5
[Pipeline] stage
[Pipeline] { (new)
[Pipeline] echo
["test 0":org.jenkinsci.plugins.workflow.cps.CpsClosure2@b42371, "test 1":org.jenkinsci.plugins.workflow.cps.CpsClosure2@1fd1631, "test 2":org.jenkinsci.plugins.workflow.cps.CpsClosure2@17e2b9d, "test 3":org.jenkinsci.plugins.workflow.cps.CpsClosure2@8ff06f, "test 4":org.jenkinsci.plugins.workflow.cps.CpsClosure2@1c1669d, "test 5":org.jenkinsci.plugins.workflow.cps.CpsClosure2@af7db5]
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS



This looks that it should be working, but when I change    echo "${run}" to  parallel (run)   (or parallel ($run) / parallel "$run" etc...)
all i get is:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 16: Nothing to execute within stage "new" @ line 16, column 9.
           stage('new'){
           ^
1 error

	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1073)
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
	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.reparse(CpsGroovyShell.java:67)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:430)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:393)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:238)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:404)
Finished: FAILURE

Bill Dennis

unread,
Mar 22, 2017, 10:42:39 AM3/22/17
to Jenkins Users
You need to put the parallel in a script section like this (I chnanged the node tag to 'windows' as I have no executors on the master):

def run = [:]
for (int i = 0; i <= 5; i++) {
 println
"adding $i"
 
def currentRun = {

 node
('windows') {

 echo
"hello $i"
 
}
 
}
 run
.put("\"test $i\"", currentRun)
}

pipeline
{
 agent none
 stages
{
 stage
('new') {
 steps
{

 script
{
 parallel
(run)
 
}
 
}
 
}
 
}
}

Also you don't need to do bat "echo" you can just do this, your bat step failed for me:

echo "hello $i"


--Bill

Tomas Pekarovic

unread,
Mar 22, 2017, 10:53:25 AM3/22/17
to jenkins...@googlegroups.com
Thank YOU you saved my life... that script was missing there

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/_uhQzsbn7l8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b28ec2fe-3a20-40e2-8717-a540d134b99e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages