title: How to dynamically trigger build jobs?
body: <p>I've got a Jenkins pipeline that triggers multiple build jobs on a single project. Each build job has different parameters that dynamically get generated during the job. There's also a string parameter on which slave the job should run on. That list is a multi-line string that gets split by \n.</p>
  
  <p>This is what I've got:</p>
  
  <pre><code>def projectName = "${PROJECT_NAME}"
  def slaveList = "${SLAVE_LIST}".split("\n")
  
  def gradleTasks = "${GRADLE_TASKS}"
  
  def slaveClosure = { slaveNum -&gt;
      build job: projectName, parameters: [
                      [$class: 'LabelParameterValue', name: 'slaveAol', label: slaveList[slaveNum]],
                      [$class: 'StringParameterValue', name: 'gradleTasks', value: gradleTasks]
                  ]
  }
  
  def parallelSlaveMap = [:]
  for (int i = 0; i &lt; slaveList.size(); i++) {
      parallelSlaveMap.put("slave${i}", slaveClosure(i))
  }
  
  parallel(parallelSlaveMap)
  </code></pre>
  
  <p>But this got me the following error:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Expected a closure or failFast but found slave0=org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper@5caff0a8
      at org.jenkinsci.plugins.workflow.cps.steps.ParallelStep$DescriptorImpl.newInstance(ParallelStep.java:202)
      at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:134)
      at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:113)
      at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151)
      at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:21)
      at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:115)
      at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:103)
      at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
      at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
      at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:15)
      at WorkflowScript.run(WorkflowScript:44)
  </code></pre>
  
  <p>For reference, line 44 in the script is the "parallel" line.</p>
  
  <p>What am I doing wrong? I'm not sure if there's a simpler way to dynamically create parallel build jobs based on a parameter list of slaves.</p>