コード例 #1
0
 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));
   }
 }