Browse Source

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
tags/0.1.3^0
Timothy Chavez 3 years ago
parent
commit
2f10c6a06f
1 changed files with 15 additions and 0 deletions
  1. 15
    0
      src/main/java/hudson/plugins/gearman/StartJobWorker.java

+ 15
- 0
src/main/java/hudson/plugins/gearman/StartJobWorker.java View File

@@ -28,6 +28,8 @@ import hudson.model.Cause;
28 28
 import hudson.model.Computer;
29 29
 import hudson.model.Hudson;
30 30
 import hudson.model.Queue;
31
+import hudson.model.labels.LabelAtom;
32
+import hudson.model.Node;
31 33
 import hudson.model.TextParameterValue;
32 34
 import hudson.model.queue.QueueTaskFuture;
33 35
 import hudson.slaves.OfflineCause;
@@ -37,6 +39,7 @@ import java.util.Date;
37 39
 import java.util.HashMap;
38 40
 import java.util.List;
39 41
 import java.util.Map;
42
+import java.util.Set;
40 43
 import java.util.concurrent.TimeUnit;
41 44
 import java.util.concurrent.TimeoutException;
42 45
 
@@ -99,6 +102,18 @@ public class StartJobWorker extends AbstractGearmanFunction {
99 102
        if (result != null) {
100 103
            data.put("result", result.toString());
101 104
        }
105
+
106
+       ArrayList<String> nodeLabels = new ArrayList<String>();
107
+       Node node = build.getBuiltOn();
108
+       if (node != null) {
109
+           Set<LabelAtom> nodeLabelAtoms = node.getAssignedLabels();
110
+           for (LabelAtom labelAtom : nodeLabelAtoms) {
111
+               nodeLabels.add(labelAtom.getDisplayName());
112
+           }
113
+       }
114
+       data.put("node_labels", nodeLabels);
115
+       data.put("node_name", node.getNodeName());
116
+
102 117
        Gson gson = new Gson();
103 118
        return gson.toJson(data);
104 119
    }

Loading…
Cancel
Save