@@ -76,6 +76,7 @@ public final void preOnline(final Computer computer, Channel channel, FilePath r
76
76
throws IOException , InterruptedException {
77
77
try {
78
78
cacheAndRefreshModel (computer , channel );
79
+ saveNodeLabel (computer .getNode ());
79
80
} catch (Exception e ) {
80
81
String name = "unnamed agent" ; // built-in (and others) may not have a name during preOnline
81
82
if (computer != null && !computer .getName ().isEmpty ()) {
@@ -115,6 +116,7 @@ public final void cacheAndRefreshModel(final Computer computer, VirtualChannel c
115
116
/** When any computer has changed, update the platform labels according to the configuration. */
116
117
@ Override
117
118
public final void onConfigurationChange () {
119
+ LOGGER .log (Level .FINEST , "onConfigurationChange() called to refresh platform labels" );
118
120
synchronized (nodePlatformProperties ) {
119
121
nodePlatformProperties .forEach ((node , labels ) -> {
120
122
refreshModel (node );
@@ -144,15 +146,13 @@ private void logUpdateNodeException(Node node, IOException e) {
144
146
}
145
147
146
148
@ SuppressFBWarnings (value = "CRLF_INJECTION_LOGS" , justification = "CRLF not allowed in label display names" )
147
- private void logUpdateNodeResult (
148
- boolean result , Node node , Collection <LabelAtom > labels , Set <LabelAtom > assignedLabels ) {
149
+ private void logUpdateNodeResult (boolean result , Node node , Set <LabelAtom > assignedLabels ) {
149
150
LOGGER .log (
150
151
Level .FINEST ,
151
152
String .format (
152
- "Update of node '%s' %s with labels %s and assigned labels %s" ,
153
+ "Update of node '%s' %s with assigned labels %s" ,
153
154
node .getDisplayName (),
154
155
result ? "succeeded" : "failed" ,
155
- Arrays .toString (labels .toArray ()),
156
156
Arrays .toString (assignedLabels .toArray ())));
157
157
}
158
158
/**
@@ -166,21 +166,37 @@ final void refreshModel(final Computer computer) {
166
166
if (node != null ) {
167
167
Collection <LabelAtom > labels = getLabelsForNode (node );
168
168
nodeLabels .put (node , labels );
169
- Set <LabelAtom > assignedLabels = node .getAssignedLabels ();
170
- try {
171
- // Save the node to ensure label will see the node updated when platform details are added (or
172
- // updated).
173
- // This will ensure a node has the same state if we were adding labels via the UI.
174
- // See JENKINS-72224
175
- boolean result = Jenkins .get ().updateNode (node );
176
- logUpdateNodeResult (result , node , labels , assignedLabels );
177
- } catch (IOException e ) {
178
- logUpdateNodeException (node , e );
179
- }
169
+ node .getAssignedLabels ();
180
170
}
181
171
}
182
172
}
183
173
174
+ /**
175
+ * Save the node to ensure label will see the node updated when platform details are added (or
176
+ * updated).
177
+ * This will ensure a node has the same state if we were adding labels via the UI.
178
+ * See JENKINS-72224
179
+ *
180
+ * @param node Node whose labels should be saved
181
+ */
182
+ final void saveNodeLabel (Node node ) {
183
+ if (node == null ) {
184
+ LOGGER .log (Level .FINEST , "Node is null. Unable to save labels and update node." );
185
+ return ;
186
+ }
187
+ Set <LabelAtom > assignedLabels = node .getAssignedLabels ();
188
+ try {
189
+ // Save the node to ensure label will see the node updated when platform details are added (or
190
+ // updated).
191
+ // This will ensure a node has the same state if we were adding labels via the UI.
192
+ // See JENKINS-72224
193
+ boolean result = Jenkins .get ().updateNode (node );
194
+ logUpdateNodeResult (result , node , assignedLabels );
195
+ } catch (IOException e ) {
196
+ logUpdateNodeException (node , e );
197
+ }
198
+ }
199
+
184
200
/**
185
201
* Return PlatformDetails of the computer.
186
202
*
0 commit comments