Skip to content
Permalink
Browse files

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

…onality OK, needs tests and javadocs
  • Loading branch information...
sophistifunk committed Dec 12, 2017
1 parent 3ff1439 commit b32359edb37879772ffba7671cc565b994ec1e2e
@@ -3,3 +3,5 @@ work
.project
.classpath
.settings
.idea/
*.iml
@@ -6,33 +6,9 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.AbortException;
import hudson.console.ModelHyperlinkNote;
import hudson.model.Action;
import hudson.model.Cause;
import hudson.model.CauseAction;
import hudson.model.Computer;
import hudson.model.Describable;
import hudson.model.Executor;
import hudson.model.Item;
import hudson.model.Job;
import hudson.model.ParameterDefinition;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Queue;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.*;
import hudson.model.queue.QueueTaskFuture;
import hudson.model.queue.ScheduleResult;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import org.jenkinsci.plugins.workflow.actions.LabelAction;
@@ -41,6 +17,16 @@
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class BuildTriggerStepExecution extends AbstractStepExecutionImpl {

private static final Logger LOGGER = Logger.getLogger(BuildTriggerStepExecution.class.getName());
@@ -65,18 +51,23 @@ public boolean start() throws Exception {
// TODO find some way of allowing ComputedFolders to hook into the listener code
throw new AbortException("Waiting for non-job items is not supported");
}

List<Action> actions = new ArrayList<>();
actions.add(new CauseAction(new Cause.UpstreamCause(invokingRun)));
actions.add(new BuildUpstreamNodeAction(node, invokingRun));

if (item instanceof ParameterizedJobMixIn.ParameterizedJob) {
final ParameterizedJobMixIn.ParameterizedJob project = (ParameterizedJobMixIn.ParameterizedJob) item;
listener.getLogger().println("Scheduling project: " + ModelHyperlinkNote.encodeTo(project));

node.addAction(new LabelAction(Messages.BuildTriggerStepExecution_building_(project.getFullDisplayName())));
List<Action> actions = new ArrayList<>();

if (step.getWait()) {
StepContext context = getContext();
actions.add(new BuildTriggerAction(context, step.isPropagate()));
LOGGER.log(Level.FINER, "scheduling a build of {0} from {1}", new Object[]{project, context});
}
actions.add(new CauseAction(new Cause.UpstreamCause(invokingRun)));

List<ParameterValue> parameters = step.getParameters();
if (parameters != null) {
parameters = completeDefaultParameters(parameters, (Job) project);
@@ -103,13 +94,12 @@ protected Job asJob() {
Queue.Task task = (Queue.Task) item;
listener.getLogger().println("Scheduling item: " + ModelHyperlinkNote.encodeTo(item));
node.addAction(new LabelAction(Messages.BuildTriggerStepExecution_building_(task.getFullDisplayName())));
List<Action> actions = new ArrayList<>();
if (step.getWait()) {
StepContext context = getContext();
actions.add(new BuildTriggerAction(context, step.isPropagate()));
LOGGER.log(Level.FINER, "scheduling a build of {0} from {1}", new Object[]{task, context});
}
actions.add(new CauseAction(new Cause.UpstreamCause(invokingRun)));

Integer quietPeriod = step.getQuietPeriod();
if (quietPeriod == null) {
try {
@@ -0,0 +1,45 @@
package org.jenkinsci.plugins.workflow.support.steps.build;

import hudson.model.InvisibleAction;
import hudson.model.Run;
import org.jenkinsci.plugins.workflow.graph.FlowNode;

import java.util.Objects;

// TODO: Javadocs for all this
public class BuildUpstreamNodeAction extends InvisibleAction {

private final String upstreamNodeId;
private final String upstreamRunId;

public BuildUpstreamNodeAction(FlowNode node, Run<?, ?> invokingRun) {
this.upstreamNodeId = node.getId();
this.upstreamRunId = invokingRun.getExternalizableId();
}

public String getUpstreamNodeId() {
return upstreamNodeId;
}

public String getUpstreamRunId() {
return upstreamRunId;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BuildUpstreamNodeAction that = (BuildUpstreamNodeAction) o;
return Objects.equals(upstreamNodeId, that.upstreamNodeId) &&
Objects.equals(upstreamRunId, that.upstreamRunId);
}

@Override
public int hashCode() {
return Objects.hash(upstreamNodeId, upstreamRunId);
}
}

0 comments on commit b32359e

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