Skip to content
Permalink
Browse files
[FIXED JENKINS-26122] Prepend parallel step execution logs with the b…
…ranch label

Originally-Committed-As: 26c0b445561881be1296309e19a6ed5eb6b8e0ea
  • Loading branch information
tfennelly committed Mar 6, 2015
1 parent eaf87cc commit 2aafd8797ba02f43de847c463bd278343dcb633e
@@ -331,4 +331,68 @@ public void invisibleParallelBranch() throws Exception {
}
});
}

@Test
@Issue("JENKINS-26122")
public void parallelBranchLabels() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
p = jenkins().createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition(join(
"node {\n" +
" parallel( \n" +
" a: { \n" +
" echo('echo a');\n" +
" echo('echo a');\n" +
" }, \n" +
" b: { \n" +
" echo('echo b'); \n" +
" echo('echo b'); \n" +
" }\n" +
" )\n" +
"}\n"
)));

startBuilding().get();
assertBuildCompletedSuccessfully();

// Check that the individual labeled lines are as expected
List<String> logLines = b.getLog(50);
assertGoodLabeledLogs(logLines);

// Check that the logs are printed in the right sequence e.g. that a
// "[a] Running: Print Message" is followed by a "[a] echo a"
assertGoodSequence("a", logLines);
assertGoodSequence("b", logLines);
}
private void assertGoodLabeledLogs(List<String> logLines) {
for (int i = 0; i < logLines.size(); i++) {
String logLine = logLines.get(i);
if (logLine.startsWith("[a] ")) {
assertGoodLabeledLog("a", logLine);
} else if (logLine.startsWith("[b] ")) {
assertGoodLabeledLog("b", logLine);
}
}
}
private void assertGoodLabeledLog(String label, String logLine) {
List<String> possibleLogLines = Arrays.asList(
String.format("[%s] Running: Parallel branch: %s", label, label),
String.format("[%s] Running: Print Message", label),
String.format("[%s] echo %s", label, label)
);
assertTrue(possibleLogLines.contains(logLine));
}
private void assertGoodSequence(String label, List<String> logLines) {
String running = String.format("[%s] Running: Print Message", label);
String echo = String.format("[%s] echo %s", label, label);

for (int i = 0; i < logLines.size() - 1; i++) { // skip the last log line in this loop
if (logLines.get(i).equals(running)) {
assertEquals(echo, logLines.get(i + 1));
}
}
}
});
}
}
@@ -4,7 +4,7 @@
import groovy.lang.Closure;
import hudson.Extension;
import hudson.model.TaskListener;
import org.jenkinsci.plugins.workflow.actions.LabelAction;
import org.jenkinsci.plugins.workflow.actions.BodyExecutionLabelAction;
import org.jenkinsci.plugins.workflow.cps.CpsVmThreadOnly;
import org.jenkinsci.plugins.workflow.cps.persistence.PersistIn;
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
@@ -47,11 +47,11 @@ public StepExecution start(StepContext context) throws Exception {
}

@PersistIn(FLOW_NODE)
public static class ParallelLabelAction extends LabelAction {
public static class ParallelLabelAction extends BodyExecutionLabelAction {
private final String branchName;

ParallelLabelAction(String branchName) {
super(null);
super(branchName);
this.branchName = branchName;
}

0 comments on commit 2aafd87

Please sign in to comment.