Navigation Menu

Skip to content

Commit

Permalink
[JENKINS-16334] Change to store label
Browse files Browse the repository at this point in the history
Get master label rather than fixed string
  • Loading branch information
cjo9900 committed Jan 29, 2013
1 parent 1c15f7b commit f0f493d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Expand Up @@ -41,20 +41,20 @@
* @author Chris Johnson
*/
public class NodeAction extends InvisibleAction implements LabelAssignmentAction, Queue.QueueAction, BuildBadgeAction {
private final String nodename;
private final Label nodeLabel;

public NodeAction(String nodename) {
this.nodename = nodename;
public NodeAction(Label nodeLabel) {
this.nodeLabel = nodeLabel;
}

public Label getAssignedLabel(SubTask task) {
return Label.get(nodename);
return nodeLabel;
}

public boolean shouldSchedule(List<Action> actions) {
// see if there is already a matching action with same node
for (NodeAction other:Util.filter(actions, NodeAction.class)) {
if(this.nodename.equals(other.nodename)){
if(this.nodeLabel.equals(other.nodeLabel)){
// there is already a task for this node.
return false;
}
Expand All @@ -65,6 +65,6 @@ public boolean shouldSchedule(List<Action> actions) {
* @return the tooltip
*/
public String getTooltip() {
return nodename;
return nodeLabel.getDisplayName();
}
}
Expand Up @@ -8,8 +8,11 @@
import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.model.Descriptor;
import hudson.model.Label;
import hudson.model.Node;
import hudson.model.TaskListener;
import java.io.IOException;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.DataBoundConstructor;

/**
Expand All @@ -24,15 +27,18 @@ public NodeParameters() {

@Override
public Action getAction(AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException, DontTriggerException {
String nodename = build.getBuiltOnStr();
Node node = build.getBuiltOn();
Label nodeLabel;
// master does not return a node name so add it explicitly.
if(nodename == "") {
nodename = "master";
if(node == null) {
nodeLabel = Jenkins.getInstance().getSelfLabel();
} else {
nodeLabel = node.getSelfLabel();
}
listener.getLogger().println("current node is " + nodename);
return new NodeAction(nodename);
listener.getLogger().println("Returning node parameter for " + nodeLabel.getDisplayName());
return new NodeAction(nodeLabel);
}

@Extension
public static class DescriptorImpl extends Descriptor<AbstractBuildParameters> {
@Override
Expand Down

0 comments on commit f0f493d

Please sign in to comment.