Send node labels back on build completion

Zuul will not necessarily know which node type the job it dispatches
to Jenkins will run on, so we send that information back to Zuul on
build completion so it can use it to submit metrics in that context.

Change-Id: Ibca938fcf8a65facd7e39dab4eb994dfc637722a
This commit is contained in:
Timothy Chavez 2015-08-20 00:14:19 -05:00
parent 08e9c429de
commit c853389c26
1 changed files with 14 additions and 0 deletions

View File

@ -28,6 +28,8 @@ import hudson.model.Cause;
import hudson.model.Computer;
import hudson.model.Hudson;
import hudson.model.Queue;
import hudson.model.labels.LabelAtom;
import hudson.model.Node;
import hudson.model.TextParameterValue;
import hudson.model.queue.QueueTaskFuture;
import hudson.slaves.OfflineCause;
@ -37,6 +39,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -99,6 +102,17 @@ public class StartJobWorker extends AbstractGearmanFunction {
if (result != null) {
data.put("result", result.toString());
}
ArrayList<String> nodeLabels = new ArrayList<String>();
Node node = build.getBuiltOn();
if ( node != null ) {
Set<LabelAtom> nodeLabelAtoms = node.getAssignedLabels();
for (LabelAtom labelAtom : nodeLabelAtoms) {
nodeLabels.add(labelAtom.getDisplayName());
}
}
data.put("node_labels", nodeLabels);
Gson gson = new Gson();
return gson.toJson(data);
}