Skip to content

Commit

Permalink
feature/JENKINS-38339-link-downstream-builds-to-trigger-node * Add un…
Browse files Browse the repository at this point in the history
…it test, javadocs, bump parent-pom to run tests from Idea
  • Loading branch information
sophistifunk committed Dec 12, 2017
1 parent b32359e commit 0bb93ea
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.33</version>
<version>2.35</version>
<relativePath />
</parent>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Expand Up @@ -6,7 +6,15 @@

import java.util.Objects;

// TODO: Javadocs for all this
/**
* Attached to newly-created builds in order to point back to the triggering FlowNode.
*
* We annotate the downstream build instead of upstream in order to support no-wait builds,
* because the downstream run id is not available when they're still queued.
*
* Needed for Blue Ocean to annotate the correct step.
* @see: https://issues.jenkins-ci.org/browse/JENKINS-38339
*/
public class BuildUpstreamNodeAction extends InvisibleAction {

private final String upstreamNodeId;
Expand Down
Expand Up @@ -39,6 +39,8 @@
import static org.hamcrest.Matchers.nullValue;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
Expand All @@ -61,7 +63,7 @@
import org.jvnet.hudson.test.recipes.LocalData;

public class BuildTriggerStepTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsRule j = new JenkinsRule();
@Rule public LoggerRule logging = new LoggerRule();
Expand Down Expand Up @@ -93,6 +95,30 @@ public class BuildTriggerStepTest {
j.assertLogContains("ds.result=FAILURE", j.buildAndAssertSuccess(us));
}

@Issue("JENKINS-38339")
@Test public void upstreamNodeAction() throws Exception {
FreeStyleProject downstream = j.createFreeStyleProject("downstream");
WorkflowJob upstream = j.jenkins.createProject(WorkflowJob.class, "upstream");

upstream.setDefinition(new CpsFlowDefinition("build 'downstream'", true));
j.assertBuildStatus(Result.SUCCESS, upstream.scheduleBuild2(0));

WorkflowRun lastUpstreamRun = upstream.getLastBuild();
FreeStyleBuild lastDownstreamRun = downstream.getLastBuild();

final FlowExecution execution = lastUpstreamRun.getExecution();
List<FlowNode> nodes = execution.getCurrentHeads();
assertEquals("node count", 1, nodes.size());
FlowNode headNode = nodes.get(0);

List<BuildUpstreamNodeAction> actions = lastDownstreamRun.getActions(BuildUpstreamNodeAction.class);
assertEquals("action count", 1, actions.size());

BuildUpstreamNodeAction action = actions.get(0);
assertEquals("correct upstreamRunId", action.getUpstreamRunId(), lastUpstreamRun.getExternalizableId());
assertNotNull("valid upstreamNodeId", execution.getNode(action.getUpstreamNodeId()));
}

@SuppressWarnings("deprecation")
@Test
public void buildFolderProject() throws Exception {
Expand Down

0 comments on commit 0bb93ea

Please sign in to comment.