private void triggerAllBuildsConcurrent(AbstractBuild build, BuildListener listener) {

    final List<String> newBuildNodes = new ArrayList<String>();

    final ParametersAction origParamsAction = build.getAction(ParametersAction.class);
    final List<ParameterValue> origParams = origParamsAction.getParameters();
    final List<ParameterValue> newPrams = new ArrayList<ParameterValue>();
    for (ParameterValue parameterValue : origParams) {
      if (parameterValue instanceof LabelParameterValue) {
        if (parameterValue instanceof NodeParameterValue) {
          NodeParameterValue origNodePram = (NodeParameterValue) parameterValue;
          List<String> nextNodes = origNodePram.getNextLabels();
          if (nextNodes != null) {
            listener.getLogger().print("next nodes: " + nextNodes);
            newBuildNodes.addAll(nextNodes);
          }
        }
      } else {
        newPrams.add(parameterValue);
      }
    }
    for (String nodeName : newBuildNodes) {
      final List<String> singleNodeList = new ArrayList<String>();
      singleNodeList.add(nodeName);
      final NodeParameterValue nodeParameterValue =
          new NodeParameterValue(nodeName, singleNodeList);
      List<ParameterValue> copies = new ArrayList<ParameterValue>(newPrams);
      copies.add(nodeParameterValue); // where to do the next build
      listener.getLogger().print("schedule build on node " + nodeName);
      build
          .getProject()
          .scheduleBuild(0, new NextLabelCause(nodeName), new ParametersAction(copies));
    }
  }
 private void triggerBuilds(AbstractBuild build, BuildListener listener) {
   final ParametersAction origParamsAction = build.getAction(ParametersAction.class);
   final List<ParameterValue> origParams = origParamsAction.getParameters();
   final List<ParameterValue> newPrams = new ArrayList<ParameterValue>();
   boolean triggerNewBuild = false;
   NextLabelCause nextLabelCause = null;
   for (ParameterValue parameterValue : origParams) {
     if (parameterValue instanceof LabelParameterValue) {
       if (parameterValue instanceof NodeParameterValue) {
         NodeParameterValue origNodePram = (NodeParameterValue) parameterValue;
         final List<String> nextNodes = origNodePram.getNextLabels();
         if (nextNodes != null
             && !nextNodes.isEmpty()
             && shouldScheduleNextJob(build.getResult(), triggerIfResult)) {
           NodeParameterValue newNodeParam =
               new NodeParameterValue(origNodePram.getName(), nextNodes);
           newPrams.add(newNodeParam);
           final String nextLabel = newNodeParam.getLabel();
           if (nextLabel != null) {
             listener.getLogger().print("schedule single build on node " + nextLabel);
             nextLabelCause = new NextLabelCause(nextLabel);
             triggerNewBuild = true;
           } else {
             LOGGER.severe(
                 "can't trigger next build because next label could not be determined!");
           }
         }
       }
     } else {
       newPrams.add(parameterValue);
     }
   }
   if (triggerNewBuild) {
     // schedule the next build right away...
     // the ParametersAction will also contain the labels for the
     // next builds
     build.getProject().scheduleBuild(0, nextLabelCause, new ParametersAction(newPrams));
   }
 }