Skip to content
Permalink
Browse files

feature/JENKINS-38339-link-downstream-builds-to-trigger-node * Add un…

…it test, javadocs, bump parent-pom to run tests from Idea
  • Loading branch information...
sophistifunk committed Dec 12, 2017
1 parent b32359e commit 0bb93ea7927af7ddac8960c024089546c4dd50d1
@@ -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>
@@ -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;
@@ -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;
@@ -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();
@@ -93,6 +95,30 @@
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 {

0 comments on commit 0bb93ea

Please sign in to comment.
You can’t perform that action at this time.