-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsConfiguration.html
535 lines (469 loc) · 56.9 KB
/
JenkinsConfiguration.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
<!DOCTYPE html>
<html lang="en" data-content_root="./">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Jenkins Configuration</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/bootstrap-sphinx.css?v=fadd4351" />
<link rel="stylesheet" type="text/css" href="_static/custom.css?v=77160d70" />
<script src="_static/documentation_options.js?v=a8da1a53"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Release Checklist" href="ReleaseChecklist.html" />
<link rel="prev" title="The Automated Build Process" href="AutomatedBuildProcess.html" />
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-59110517-1', 'auto');
ga('send', 'pageview');
</script>
</head><body>
<div id="navbar" class="navbar navbar-default ">
<div class="container">
<div class="navbar-header">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://www.mantidproject.org">
</a>
<span class="navbar-text navbar-version pull-left"><b>main</b></span>
</div>
<div class="collapse navbar-collapse nav-collapse">
<ul class="nav navbar-nav">
<li class="divider-vertical"></li>
<li><a href="index.html">Home</a></li>
<li><a href="https://download.mantidproject.org">Download</a></li>
<li><a href="https://docs.mantidproject.org">User Documentation</a></li>
<li><a href="http://www.mantidproject.org/contact">Contact Us</a></li>
</ul>
<form class="navbar-form navbar-right" action="search.html" method="get">
<div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search" />
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<p>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="nav-item nav-item-0"><a href="index.html">Documentation</a> »</li>
<li class="nav-item nav-item-this"><a href="">Jenkins Configuration</a></li>
</ul>
</div> </p>
</div>
<div class="container">
<div class="row">
<div class="body col-md-12 content" role="main">
<section id="jenkins-configuration">
<span id="jenkinsconfiguration"></span><h1>Jenkins Configuration<a class="headerlink" href="#jenkins-configuration" title="Link to this heading">¶</a></h1>
<nav class="contents local" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#summary" id="id2">Summary</a></p></li>
<li><p><a class="reference internal" href="#introduction" id="id3">Introduction</a></p></li>
<li><p><a class="reference internal" href="#setting-up-a-new-agent" id="id4">Setting up a New Agent</a></p>
<ul>
<li><p><a class="reference internal" href="#windows" id="id5">Windows</a></p>
<ul>
<li><p><a class="reference internal" href="#agent-connection" id="id6">Agent Connection</a></p></li>
<li><p><a class="reference internal" href="#connecting-through-a-proxy-server" id="id7">Connecting Through a Proxy Server</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#linux" id="id8">Linux</a></p></li>
<li><p><a class="reference internal" href="#mac-os" id="id9">Mac OS</a></p>
<ul>
<li><p><a class="reference internal" href="#id1" id="id10">Agent Connection</a></p></li>
</ul>
</li>
</ul>
</li>
<li><p><a class="reference internal" href="#misc-groovy-scripts" id="id11">Misc Groovy Scripts</a></p>
<ul>
<li><p><a class="reference internal" href="#print-the-value-of-an-environment-variable-on-all-nodes" id="id12">Print the Value of an Environment Variable on All Nodes</a></p></li>
<li><p><a class="reference internal" href="#remove-directories-across-multiple-nodes" id="id13">Remove directories across multiple nodes</a></p></li>
<li><p><a class="reference internal" href="#remove-directories-from-single-node" id="id14">Remove directories from single node</a></p></li>
<li><p><a class="reference internal" href="#update-branches-for-jobs" id="id15">Update Branches For Jobs</a></p></li>
<li><p><a class="reference internal" href="#list-all-scm-urls" id="id16">List All SCM Urls</a></p></li>
<li><p><a class="reference internal" href="#update-urls-on-all-jobs" id="id17">Update Urls on All Jobs</a></p></li>
<li><p><a class="reference internal" href="#print-all-loggers" id="id18">Print All Loggers</a></p></li>
<li><p><a class="reference internal" href="#run-a-process-on-a-single-node" id="id19">Run a Process On a Single Node</a></p></li>
<li><p><a class="reference internal" href="#run-a-process-across-all-nodes" id="id20">Run a Process Across All Nodes</a></p></li>
<li><p><a class="reference internal" href="#update-default-values-for-job-parameters" id="id21">Update default values for job parameters</a></p></li>
</ul>
</li>
</ul>
</nav>
<section id="summary">
<h2><a class="toc-backref" href="#id2" role="doc-backlink">Summary</a><a class="headerlink" href="#summary" title="Link to this heading">¶</a></h2>
<p>Mantid uses the <a class="reference external" href="https://jenkins.io/">Jenkins</a> automation server to support
its continuous integration needs.
This document describes the general setup of the system.</p>
</section>
<section id="introduction">
<h2><a class="toc-backref" href="#id3" role="doc-backlink">Introduction</a><a class="headerlink" href="#introduction" title="Link to this heading">¶</a></h2>
<p>Jenkins works on a ‘controller -> agent’ principle.
The controller is responsible for orchestrating jobs and managing the agents where the work is actually performed.
The controller node is located at <a class="reference external" href="https://builds.mantidproject.org">https://builds.mantidproject.org</a> and
each facility is responsible for providing hardware to act as agents for the various required configurations.</p>
</section>
<section id="setting-up-a-new-agent">
<h2><a class="toc-backref" href="#id4" role="doc-backlink">Setting up a New Agent</a><a class="headerlink" href="#setting-up-a-new-agent" title="Link to this heading">¶</a></h2>
<section id="windows">
<h3><a class="toc-backref" href="#id5" role="doc-backlink">Windows</a><a class="headerlink" href="#windows" title="Link to this heading">¶</a></h3>
<p>First install the prerequisites tools that cannot be provided through Conda:</p>
<ol class="arabic simple">
<li><p>Install the <a class="reference external" href="https://visualstudio.microsoft.com/downloads/">Command line Visual C++ 2019 build tools</a>.
2019 matches the version used by conda-forge.
You may need to scroll to the botton and “click Older Downloads” to find it.
Once the installer has downloaded run it as administrator and select the
C++ workload.</p></li>
<li><p>Install <a class="reference external" href="https://git-scm.com/download/win">Git for Windows</a> using the
64-bit Standalone Installer. Once downloaded run it as administrator and
ensure the installation location is <code class="docutils literal notranslate"><span class="pre">C:\ProgramFiles\Git</span></code>.
When the installer has finished, open a PowerShell prompt as administrator
and run <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">config</span> <span class="pre">--system</span> <span class="pre">--get</span> <span class="pre">core.longpaths</span> <span class="pre">true</span></code> to configure
Git for long paths.</p></li>
<li><p>Configure long paths in the registry by running <code class="docutils literal notranslate"><span class="pre">regedit</span></code> from a
Powershell administrator prompt and setting the
<code class="docutils literal notranslate"><span class="pre">Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled</span></code>
key to <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p></li>
<li><p>Install Java from <a class="reference external" href="https://adoptium.net/en-GB/temurin/releases/?version=11">Adoptium</a>
Select <code class="docutils literal notranslate"><span class="pre">OS=Windows</span></code>, <code class="docutils literal notranslate"><span class="pre">Architecture=x64</span></code>, <cite>Package Type=JRE`</cite>, <code class="docutils literal notranslate"><span class="pre">Version=11</span></code>.
Install as administrator and add to that <code class="docutils literal notranslate"><span class="pre">PATH</span></code> for all users.</p></li>
<li><p>Reboot the machine</p></li>
</ol>
<section id="agent-connection">
<h4><a class="toc-backref" href="#id6" role="doc-backlink">Agent Connection</a><a class="headerlink" href="#agent-connection" title="Link to this heading">¶</a></h4>
<p>To connect the agent to Jenkins you will need to login to the controller at
<a class="reference external" href="https://builds.mantidproject.org">https://builds.mantidproject.org</a>. Once logged in:</p>
<ol class="arabic simple">
<li><p>Click “New Node” at <a class="reference external" href="https://builds.mantidproject.org/computer/">https://builds.mantidproject.org/computer/</a>.</p></li>
<li><p>It is recommended to select “Copy Existing Node” and choose another Windows-based
agent.</p></li>
<li><p>Set the name to following the pattern <code class="docutils literal notranslate"><span class="pre">FACILITY-HOSTNAME</span></code>.</p></li>
<li><p>Edit the description to describe where the machine is located.</p></li>
<li><p>Edit the <code class="docutils literal notranslate"><span class="pre">win-64</span></code> label to <code class="docutils literal notranslate"><span class="pre">xwin-64</span></code> to avoid the node being added to the
pool straight away.</p></li>
<li><p>Under the “Environment variables” section at the bottom change the values to
match the node properties, e.g. build threads to match number of cores.</p></li>
<li><p>Click “Save” to be returned to the front page of the new node.</p></li>
<li><p>On the desktop of the node visit
<a class="reference external" href="https://builds.mantidproject.org/computer">https://builds.mantidproject.org/computer</a>/<node-name>/jenkins-agent.jnlp,
where <code class="docutils literal notranslate"><span class="pre"><node-name></span></code> is the name of the node when created above.
Take note of the download location for the next step.</p></li>
<li><p>Open PowerShell as an administrator and change directory to that noted in the
previous step. Run the agent file: <cite>.jenkins-agent.jnlp</cite>.</p></li>
<li><p>In the GUI that pops up a <code class="docutils literal notranslate"><span class="pre">File</span></code> menu will appear after a few seconds</p></li>
<li><p>Click <code class="docutils literal notranslate"><span class="pre">File->Install</span> <span class="pre">Service</span></code>.</p></li>
<li><p>Check back on the Jenkins agent description page and it should be connected.</p></li>
</ol>
</section>
<section id="connecting-through-a-proxy-server">
<h4><a class="toc-backref" href="#id7" role="doc-backlink">Connecting Through a Proxy Server</a><a class="headerlink" href="#connecting-through-a-proxy-server" title="Link to this heading">¶</a></h4>
<p>It is a little more tricky to add Windows agents connected through a proxy.
To do this you must modify the Java arguments that are used to start the <code class="docutils literal notranslate"><span class="pre">jenkins-slave</span></code> process.
Once the “Install as a Windows Service” has completed you should:</p>
<ol class="arabic simple">
<li><p>Find the directory on the machine, such as <code class="docutils literal notranslate"><span class="pre">C:\Jenkins</span></code>, that was configured as the Jenkins filesystem root</p></li>
<li><p>Open the <code class="docutils literal notranslate"><span class="pre">jenkins-slave.xml</span></code> file</p></li>
<li><p>Edit the java arguments tag and add <code class="docutils literal notranslate"><span class="pre">-Dhttp.proxyHost=PROXYHOST</span> <span class="pre">-Dhttp.proxyPort=PROXYPORT</span></code> to the list</p></li>
<li><p>Save the file and restart the service (or machine)</p></li>
</ol>
</section>
</section>
<section id="linux">
<h3><a class="toc-backref" href="#id8" role="doc-backlink">Linux</a><a class="headerlink" href="#linux" title="Link to this heading">¶</a></h3>
<p>Linux-based nodes should use the Docker-based setup described
<a class="reference external" href="https://github.com/mantidproject/dockerfiles/tree/main/jenkins-node">here</a>.
The base OS does not need to be RancherOS and can be anything as long as Docker
will run.</p>
<p>The agent will connect automatically when the Docker container starts running.</p>
</section>
<section id="mac-os">
<h3><a class="toc-backref" href="#id9" role="doc-backlink">Mac OS</a><a class="headerlink" href="#mac-os" title="Link to this heading">¶</a></h3>
<p>Enable <a class="reference external" href="https://apple.stackexchange.com/a/73919">SSH (“Remote Login”) and VNC (“Remote Management”)</a>.
If you have connection issues from a non-OS X client then try adjusting your color
depth settings (True Color 32bpp works on Remmina).</p>
<p>In order to run the Qt tests, which require a connection to the windowing system,
the user that is running the Jenkins agent must be left logged in and the
automatic screen lock must be disabled.
This is most easily done by VNC - connect, log in, then disconnect.
If you see errors such as:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">_RegisterApplication</span><span class="p">(),</span> <span class="n">FAILED</span> <span class="n">TO</span> <span class="n">establish</span> <span class="n">the</span> <span class="n">default</span> <span class="n">connection</span> <span class="n">to</span> <span class="n">the</span> <span class="n">WindowServer</span><span class="p">,</span>
<span class="n">_CGSDefaultConnection</span><span class="p">()</span> <span class="ow">is</span> <span class="n">NULL</span><span class="o">.</span>
</pre></div>
</div>
<p>then no one is logged in to the system.</p>
<p>Disable saved application states that cause a dialog to be raised after a
program crash resulting in a test hanging waiting for a user to click ok on a dialog:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">defaults</span> <span class="n">write</span> <span class="n">org</span><span class="o">.</span><span class="n">python</span><span class="o">.</span><span class="n">python</span> <span class="n">NSQuitAlwaysKeepsWindows</span> <span class="o">-</span><span class="nb">bool</span> <span class="n">false</span>
<span class="n">defaults</span> <span class="n">write</span> <span class="n">org</span><span class="o">.</span><span class="n">mantidproject</span><span class="o">.</span><span class="n">MantidPlot</span> <span class="n">NSQuitAlwaysKeepsWindows</span> <span class="o">-</span><span class="nb">bool</span> <span class="n">false</span>
</pre></div>
</div>
<p>Finally, install Java 11 JRE from <a class="reference external" href="https://adoptium.net/temurin/releases/">https://adoptium.net/temurin/releases/</a> by selecting
<code class="docutils literal notranslate"><span class="pre">macOS</span></code>, <code class="docutils literal notranslate"><span class="pre">x64</span></code>, <code class="docutils literal notranslate"><span class="pre">JRE</span></code> and <code class="docutils literal notranslate"><span class="pre">11</span></code> for the respective options.
Download the <code class="docutils literal notranslate"><span class="pre">.pkg</span></code> and install following the instructions.</p>
<p>Restart the machine and ensure you leave the jenkins-agent user logged in as
per the instructions above.</p>
<section id="id1">
<h4><a class="toc-backref" href="#id10" role="doc-backlink">Agent Connection</a><a class="headerlink" href="#id1" title="Link to this heading">¶</a></h4>
<p>The Jenkins JNLP connections are maintained by a crontab entry.
The script is in the <a class="reference external" href="https://github.com/mantidproject/mantid/blob/main/buildconfig/Jenkins/jenkins-slave.sh">mantid repository</a>.
The comments at the top describe a how to customize the script for a new agent.</p>
</section>
</section>
</section>
<section id="misc-groovy-scripts">
<h2><a class="toc-backref" href="#id11" role="doc-backlink">Misc Groovy Scripts</a><a class="headerlink" href="#misc-groovy-scripts" title="Link to this heading">¶</a></h2>
<p>The following is a collection of groovy scripts that can be run either at <a class="reference external" href="https://builds.mantidproject.org/script">https://builds.mantidproject.org/script</a> (for master node) or on a given node, e.g <a class="reference external" href="https://builds.mantidproject.org/computer/isis-mantidlx3/script">isis-mantidx3</a>.
You must have admin privileges to run them.</p>
<p><a class="reference external" href="https://github.com/jenkinsci/jenkins-scripts/tree/main/scriptler">https://github.com/jenkinsci/jenkins-scripts/tree/main/scriptler</a> was helpful for coming up with some of these.</p>
<section id="print-the-value-of-an-environment-variable-on-all-nodes">
<h3><a class="toc-backref" href="#id12" role="doc-backlink">Print the Value of an Environment Variable on All Nodes</a><a class="headerlink" href="#print-the-value-of-an-environment-variable-on-all-nodes" title="Link to this heading">¶</a></h3>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">jenkins.model.*</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">hudson.model.*</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">hudson.slaves.*</span>
<span class="n">VARIABLE_NAME</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"ENV_VARIABLE_NAME"</span>
<span class="n">nodes</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Jenkins</span><span class="o">.</span><span class="na">instance</span><span class="o">.</span><span class="na">getNodes</span><span class="o">()</span>
<span class="n">println</span><span class="o">(</span><span class="s2">"Displaying values of "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">VARIABLE_NAME</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">" on all nodes"</span><span class="o">)</span>
<span class="n">println</span><span class="o">()</span>
<span class="k">for</span><span class="o">(</span><span class="n">node</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">nodes</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">node_props</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="na">nodeProperties</span><span class="o">.</span><span class="na">getAll</span><span class="o">(</span><span class="n">hudson</span><span class="o">.</span><span class="na">slaves</span><span class="o">.</span><span class="na">EnvironmentVariablesNodeProperty</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
<span class="w"> </span><span class="k">if</span><span class="o">(</span><span class="n">node_props</span><span class="o">.</span><span class="na">size</span><span class="o">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">1</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">env_vars</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node_props</span><span class="o">[</span><span class="mi">0</span><span class="o">].</span><span class="na">getEnvVars</span><span class="o">()</span>
<span class="w"> </span><span class="k">if</span><span class="o">(</span><span class="n">env_vars</span><span class="o">.</span><span class="na">containsKey</span><span class="o">(</span><span class="n">VARIABLE_NAME</span><span class="o">))</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">pv_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">env_vars</span><span class="o">.</span><span class="na">get</span><span class="o">(</span><span class="n">VARIABLE_NAME</span><span class="o">,</span><span class="w"> </span><span class="s2">""</span><span class="o">)</span>
<span class="w"> </span><span class="o">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">pv_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">VARIABLE_NAME</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">" not set."</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="n">println</span><span class="o">(</span><span class="n">node</span><span class="o">.</span><span class="na">getDisplayName</span><span class="o">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">": "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">pv_dir</span><span class="o">)</span>
<span class="w"> </span><span class="o">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">pv_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">VARIABLE_NAME</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">" not set."</span>
<span class="w"> </span><span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</section>
<section id="remove-directories-across-multiple-nodes">
<h3><a class="toc-backref" href="#id13" role="doc-backlink">Remove directories across multiple nodes</a><a class="headerlink" href="#remove-directories-across-multiple-nodes" title="Link to this heading">¶</a></h3>
<p>The example here will remove the build directories from pull request build and test jobs.
Useful, for example, when a dependency change requires a clean build.
It is advised to ensure nothing is running and pause the build queue.</p>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">hudson.model.*</span>
<span class="n">nodes</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Jenkins</span><span class="o">.</span><span class="na">instance</span><span class="o">.</span><span class="na">slaves</span>
<span class="n">JOB_PREFIX</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"pull_requests-"</span>
<span class="n">suffixes</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[</span><span class="s2">"conda-linux"</span><span class="o">,</span><span class="w"> </span><span class="s2">"conda-osx"</span><span class="o">,</span><span class="w"> </span><span class="s2">"conda-windows"</span><span class="o">];</span>
<span class="k">for</span><span class="w"> </span><span class="o">(</span><span class="n">node</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">nodes</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="o">(</span><span class="n">suffix</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">suffixes</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">FilePath</span><span class="w"> </span><span class="n">fp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="na">createPath</span><span class="o">(</span><span class="n">node</span><span class="o">.</span><span class="na">getRootPath</span><span class="o">().</span><span class="na">toString</span><span class="o">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">File</span><span class="o">.</span><span class="na">separator</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">"workspace"</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">File</span><span class="o">.</span><span class="na">separator</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">JOB_PREFIX</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">suffix</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">File</span><span class="o">.</span><span class="na">separator</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">"build"</span><span class="o">);</span>
<span class="w"> </span><span class="k">if</span><span class="o">(</span><span class="n">fp</span><span class="o">!=</span><span class="kc">null</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="n">fp</span><span class="o">.</span><span class="na">exists</span><span class="o">())</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">println</span><span class="o">(</span><span class="n">fp</span><span class="o">.</span><span class="na">toString</span><span class="o">())</span>
<span class="w"> </span><span class="n">fp</span><span class="o">.</span><span class="na">deleteRecursive</span><span class="o">()</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</section>
<section id="remove-directories-from-single-node">
<h3><a class="toc-backref" href="#id14" role="doc-backlink">Remove directories from single node</a><a class="headerlink" href="#remove-directories-from-single-node" title="Link to this heading">¶</a></h3>
<p>It is advised to take the target node offline.</p>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">hudson.model.*</span>
<span class="c1">// Example: "isis-ndw1597"</span>
<span class="n">String</span><span class="w"> </span><span class="n">agentName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o"><</span><span class="n">agent</span><span class="s">/node name></span>
<span class="s">/</span><span class="o">/</span><span class="w"> </span><span class="nl">Example:</span><span class="w"> </span><span class="s2">"pull_requests-conda-windows"</span><span class="w"> </span><span class="o">,</span><span class="w"> </span><span class="s2">"build_packages_from_branch"</span>
<span class="n">jobs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[<</span><span class="n">job</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="n">string</span><span class="o">></span><span class="w"> </span><span class="o">,</span><span class="w"> </span><span class="o"><</span><span class="n">job</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="n">string</span><span class="o">>,</span><span class="w"> </span><span class="o">...]</span>
<span class="n">nodes</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Jenkins</span><span class="o">.</span><span class="na">instance</span><span class="o">.</span><span class="na">slaves</span>
<span class="k">for</span><span class="w"> </span><span class="o">(</span><span class="n">node</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">nodes</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">if</span><span class="o">(</span><span class="n">node</span><span class="o">.</span><span class="na">toString</span><span class="o">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"hudson.slaves.DumbSlave[$agentName]"</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="o">(</span><span class="n">job</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">jobs</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">FilePath</span><span class="w"> </span><span class="n">fp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="na">createPath</span><span class="o">(</span><span class="n">node</span><span class="o">.</span><span class="na">getRootPath</span><span class="o">().</span><span class="na">toString</span><span class="o">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">File</span><span class="o">.</span><span class="na">separator</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">"workspace"</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">File</span><span class="o">.</span><span class="na">separator</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">job</span><span class="o">)</span>
<span class="w"> </span><span class="k">if</span><span class="o">(</span><span class="n">fp</span><span class="o">!=</span><span class="kc">null</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="n">fp</span><span class="o">.</span><span class="na">exists</span><span class="o">())</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">println</span><span class="o">(</span><span class="n">node</span><span class="o">.</span><span class="na">toString</span><span class="o">())</span>
<span class="w"> </span><span class="n">println</span><span class="o">(</span><span class="n">fp</span><span class="o">.</span><span class="na">toString</span><span class="o">())</span>
<span class="w"> </span><span class="n">fp</span><span class="o">.</span><span class="na">deleteRecursive</span><span class="o">()</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</section>
<section id="update-branches-for-jobs">
<h3><a class="toc-backref" href="#id15" role="doc-backlink">Update Branches For Jobs</a><a class="headerlink" href="#update-branches-for-jobs" title="Link to this heading">¶</a></h3>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">hudson.plugins.git.GitSCM</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">hudson.plugins.git.BranchSpec</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">static</span><span class="w"> </span><span class="n">com</span><span class="o">.</span><span class="na">google</span><span class="o">.</span><span class="na">common</span><span class="o">.</span><span class="na">collect</span><span class="o">.</span><span class="na">Lists</span><span class="o">.</span><span class="na">newArrayList</span><span class="o">;</span>
<span class="kt">def</span><span class="w"> </span><span class="n">NEW_BRANCH</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"*/release-next"</span>
<span class="c1">// Access to the Hudson Singleton</span>
<span class="kt">def</span><span class="w"> </span><span class="n">jenkins</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">jenkins</span><span class="o">.</span><span class="na">model</span><span class="o">.</span><span class="na">Jenkins</span><span class="o">.</span><span class="na">instance</span><span class="o">;</span>
<span class="c1">// Retrieve matching jobs</span>
<span class="kt">def</span><span class="w"> </span><span class="n">allItems</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">jenkins</span><span class="o">.</span><span class="na">items</span>
<span class="kt">def</span><span class="w"> </span><span class="n">chosenJobs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">allItems</span><span class="o">.</span><span class="na">findAll</span><span class="o">{</span><span class="n">job</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">job</span><span class="o">.</span><span class="na">name</span><span class="w"> </span><span class="o">=-</span><span class="w"> </span><span class="s">/release_/</span><span class="o">};</span>
<span class="n">println</span><span class="w"> </span><span class="s2">"Updating branch for chosen jobs to $NEW_BRANCH"</span>
<span class="n">println</span><span class="w"> </span><span class="s2">""</span>
<span class="c1">// Do work</span>
<span class="n">chosenJobs</span><span class="o">.</span><span class="na">each</span><span class="w"> </span><span class="o">{</span><span class="w"> </span><span class="n">job</span><span class="w"> </span><span class="o">-></span>
<span class="w"> </span><span class="kt">def</span><span class="w"> </span><span class="n">scm</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">job</span><span class="o">.</span><span class="na">scm</span><span class="o">;</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="o">(</span><span class="n">scm</span><span class="w"> </span><span class="k">instanceof</span><span class="w"> </span><span class="n">GitSCM</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="n">job</span><span class="o">.</span><span class="na">name</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="s2">"release_nightly_deploy"</span><span class="w"> </span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="c1">//def newScm = scm.clone()</span>
<span class="w"> </span><span class="n">println</span><span class="w"> </span><span class="s2">"Updating branch for "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">job</span><span class="o">.</span><span class="na">name</span>
<span class="w"> </span><span class="n">scm</span><span class="o">.</span><span class="na">branches</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">newArrayList</span><span class="o">(</span><span class="k">new</span><span class="w"> </span><span class="n">BranchSpec</span><span class="o">(</span><span class="n">NEW_BRANCH</span><span class="o">))</span>
<span class="w"> </span><span class="n">println</span><span class="w"> </span><span class="s2">"Branch for "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">job</span><span class="o">.</span><span class="na">name</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">": "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">scm</span><span class="o">.</span><span class="na">branches</span>
<span class="w"> </span><span class="n">println</span><span class="w"> </span><span class="s2">""</span>
<span class="w"> </span><span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</section>
<section id="list-all-scm-urls">
<h3><a class="toc-backref" href="#id16" role="doc-backlink">List All SCM Urls</a><a class="headerlink" href="#list-all-scm-urls" title="Link to this heading">¶</a></h3>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">jenkins.model.*</span><span class="o">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">hudson.model.*</span><span class="o">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">hudson.tasks.*</span><span class="o">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">hudson.plugins.git.*</span><span class="o">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">org.eclipse.jgit.transport.RemoteConfig</span><span class="o">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">org.eclipse.jgit.transport.URIish</span><span class="o">;</span>
<span class="k">for</span><span class="o">(</span><span class="n">project</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">Hudson</span><span class="o">.</span><span class="na">instance</span><span class="o">.</span><span class="na">items</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">try</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">scm</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">project</span><span class="o">.</span><span class="na">scm</span><span class="o">;</span>
<span class="w"> </span><span class="o">}</span><span class="w"> </span><span class="k">catch</span><span class="o">(</span><span class="n">Exception</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">continue</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="o">(</span><span class="n">scm</span><span class="w"> </span><span class="k">instanceof</span><span class="w"> </span><span class="n">hudson</span><span class="o">.</span><span class="na">plugins</span><span class="o">.</span><span class="na">git</span><span class="o">.</span><span class="na">GitSCM</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="o">(</span><span class="n">RemoteConfig</span><span class="w"> </span><span class="n">cfg</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">scm</span><span class="o">.</span><span class="na">getRepositories</span><span class="o">())</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="o">(</span><span class="n">URIish</span><span class="w"> </span><span class="n">uri</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">cfg</span><span class="o">.</span><span class="na">getURIs</span><span class="o">())</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">println</span><span class="o">(</span><span class="s2">"SCM "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">uri</span><span class="o">.</span><span class="na">toString</span><span class="o">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">" for project "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">project</span><span class="o">);</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</section>
<section id="update-urls-on-all-jobs">
<h3><a class="toc-backref" href="#id17" role="doc-backlink">Update Urls on All Jobs</a><a class="headerlink" href="#update-urls-on-all-jobs" title="Link to this heading">¶</a></h3>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">jenkins.model.*</span><span class="o">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">hudson.model.*</span><span class="o">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">hudson.tasks.*</span><span class="o">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">hudson.plugins.git.*</span><span class="o">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">org.eclipse.jgit.transport.RemoteConfig</span><span class="o">;</span>
<span class="kt">def</span><span class="w"> </span><span class="nf">modifyGitUrl</span><span class="o">(</span><span class="n">url</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">if</span><span class="o">(</span><span class="n">url</span><span class="o">.</span><span class="na">startsWith</span><span class="o">(</span><span class="s1">'git://'</span><span class="o">))</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="s2">"https://"</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">url</span><span class="o">.</span><span class="na">substring</span><span class="o">(</span><span class="mi">6</span><span class="o">);</span>
<span class="w"> </span><span class="o">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">url</span><span class="o">;</span>
<span class="w"> </span><span class="o">}</span>
<span class="o">}</span>
<span class="k">for</span><span class="o">(</span><span class="n">project</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">Hudson</span><span class="o">.</span><span class="na">instance</span><span class="o">.</span><span class="na">items</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">try</span><span class="o">{</span>
<span class="w"> </span><span class="n">oldScm</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">project</span><span class="o">.</span><span class="na">scm</span><span class="o">;</span>
<span class="w"> </span><span class="o">}</span><span class="w"> </span><span class="k">catch</span><span class="o">(</span><span class="n">Exception</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">continue</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="o">(</span><span class="n">oldScm</span><span class="w"> </span><span class="k">instanceof</span><span class="w"> </span><span class="n">hudson</span><span class="o">.</span><span class="na">plugins</span><span class="o">.</span><span class="na">git</span><span class="o">.</span><span class="na">GitSCM</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="kt">def</span><span class="w"> </span><span class="n">newUserRemoteConfigs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">oldScm</span><span class="o">.</span><span class="na">userRemoteConfigs</span><span class="o">.</span><span class="na">collect</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">UserRemoteConfig</span><span class="o">(</span><span class="n">modifyGitUrl</span><span class="o">(</span><span class="n">it</span><span class="o">.</span><span class="na">url</span><span class="o">),</span><span class="w"> </span><span class="n">it</span><span class="o">.</span><span class="na">name</span><span class="o">,</span><span class="w"> </span><span class="n">it</span><span class="o">.</span><span class="na">refspec</span><span class="o">,</span><span class="w"> </span><span class="n">it</span><span class="o">.</span><span class="na">credentialsId</span><span class="o">)</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="kt">def</span><span class="w"> </span><span class="n">newScm</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">GitSCM</span><span class="o">(</span><span class="n">newUserRemoteConfigs</span><span class="o">,</span><span class="w"> </span><span class="n">oldScm</span><span class="o">.</span><span class="na">branches</span><span class="o">,</span><span class="w"> </span><span class="n">oldScm</span><span class="o">.</span><span class="na">doGenerateSubmoduleConfigurations</span><span class="o">,</span>
<span class="w"> </span><span class="n">oldScm</span><span class="o">.</span><span class="na">submoduleCfg</span><span class="o">,</span><span class="w"> </span><span class="n">oldScm</span><span class="o">.</span><span class="na">browser</span><span class="o">,</span><span class="w"> </span><span class="n">oldScm</span><span class="o">.</span><span class="na">gitTool</span><span class="o">,</span><span class="w"> </span><span class="n">oldScm</span><span class="o">.</span><span class="na">extensions</span><span class="o">)</span>
<span class="w"> </span><span class="n">project</span><span class="o">.</span><span class="na">scm</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">newScm</span><span class="o">;</span>
<span class="w"> </span><span class="n">project</span><span class="o">.</span><span class="na">save</span><span class="o">();</span>
<span class="w"> </span><span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</section>
<section id="print-all-loggers">
<h3><a class="toc-backref" href="#id18" role="doc-backlink">Print All Loggers</a><a class="headerlink" href="#print-all-loggers" title="Link to this heading">¶</a></h3>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">java.util.logging.*</span><span class="o">;</span>
<span class="n">LogManager</span><span class="o">.</span><span class="na">getLogManager</span><span class="o">().</span><span class="na">getLoggerNames</span><span class="o">().</span><span class="na">each</span><span class="o">()</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">println</span><span class="w"> </span><span class="s2">"${it}"</span><span class="o">;</span>
<span class="o">}</span>
</pre></div>
</div>
</section>
<section id="run-a-process-on-a-single-node">
<h3><a class="toc-backref" href="#id19" role="doc-backlink">Run a Process On a Single Node</a><a class="headerlink" href="#run-a-process-on-a-single-node" title="Link to this heading">¶</a></h3>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="n">Process</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"cmd /c dir"</span><span class="o">.</span><span class="na">execute</span><span class="o">()</span>
<span class="n">println</span><span class="w"> </span><span class="s2">"${p.text}"</span>
<span class="c1">// kill process on windows slave</span>
<span class="n">Process</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"cmd /c Taskkill /F /IM MantidPlot.exe"</span><span class="o">.</span><span class="na">execute</span><span class="o">()</span>
<span class="n">println</span><span class="w"> </span><span class="s2">"${p.text}"</span>
</pre></div>
</div>
</section>
<section id="run-a-process-across-all-nodes">
<h3><a class="toc-backref" href="#id20" role="doc-backlink">Run a Process Across All Nodes</a><a class="headerlink" href="#run-a-process-across-all-nodes" title="Link to this heading">¶</a></h3>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">hudson.util.RemotingDiagnostics</span><span class="o">;</span>
<span class="k">for</span><span class="w"> </span><span class="o">(</span><span class="n">slave</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">hudson</span><span class="o">.</span><span class="na">model</span><span class="o">.</span><span class="na">Hudson</span><span class="o">.</span><span class="na">instance</span><span class="o">.</span><span class="na">slaves</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">println</span><span class="w"> </span><span class="n">slave</span><span class="o">.</span><span class="na">name</span><span class="o">;</span>
<span class="w"> </span><span class="c1">// is it connected?</span>
<span class="w"> </span><span class="k">if</span><span class="o">(</span><span class="n">slave</span><span class="o">.</span><span class="na">getChannel</span><span class="o">())</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">println</span><span class="w"> </span><span class="n">RemotingDiagnostics</span><span class="o">.</span><span class="na">executeGroovy</span><span class="o">(</span><span class="s2">"println \"ls\".execute().text"</span><span class="o">,</span><span class="w"> </span><span class="n">slave</span><span class="o">.</span><span class="na">getChannel</span><span class="o">());</span>
<span class="w"> </span><span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</section>
<section id="update-default-values-for-job-parameters">
<h3><a class="toc-backref" href="#id21" role="doc-backlink">Update default values for job parameters</a><a class="headerlink" href="#update-default-values-for-job-parameters" title="Link to this heading">¶</a></h3>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">hudson.model.*</span>
<span class="kt">def</span><span class="w"> </span><span class="n">SUFFIX_VARIABLE</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"PACKAGE_SUFFIX"</span>
<span class="kt">def</span><span class="w"> </span><span class="n">NEW_SUFFIX</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"nightly"</span>
<span class="c1">// Access to the Hudson Singleton</span>
<span class="kt">def</span><span class="w"> </span><span class="n">jenkins</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">jenkins</span><span class="o">.</span><span class="na">model</span><span class="o">.</span><span class="na">Jenkins</span><span class="o">.</span><span class="na">instance</span><span class="o">;</span>
<span class="c1">// Retrieve matching jobs</span>
<span class="kt">def</span><span class="w"> </span><span class="n">chosenJobs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[</span><span class="s2">"release_clean-rhel7"</span><span class="o">]</span><span class="w"> </span><span class="c1">//, "release_clean-ubuntu-16.04", "release_clean-ubuntu"]</span>
<span class="n">println</span><span class="w"> </span><span class="s2">"Updating default package suffix for chosen jobs to ${NEW_SUFFIX}"</span>
<span class="n">println</span><span class="w"> </span><span class="s2">""</span>
<span class="c1">// Do work</span>
<span class="n">chosenJobs</span><span class="o">.</span><span class="na">each</span><span class="w"> </span><span class="o">{</span><span class="w"> </span><span class="n">jobName</span><span class="w"> </span><span class="o">-></span>
<span class="w"> </span><span class="n">job</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">jenkins</span><span class="o">.</span><span class="na">getItem</span><span class="o">(</span><span class="n">jobName</span><span class="o">)</span>
<span class="w"> </span><span class="n">println</span><span class="o">(</span><span class="n">job</span><span class="o">)</span>
<span class="w"> </span><span class="n">paramsDef</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">job</span><span class="o">.</span><span class="na">getAction</span><span class="o">(</span><span class="n">ParametersDefinitionProperty</span><span class="o">)</span>
<span class="w"> </span><span class="n">params</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">paramsDef</span><span class="o">.</span><span class="na">getParameterDefinitions</span><span class="o">()</span>
<span class="w"> </span><span class="n">params</span><span class="o">.</span><span class="na">each</span><span class="w"> </span><span class="o">{</span><span class="w"> </span><span class="n">it</span><span class="w"> </span><span class="o">-></span>
<span class="w"> </span><span class="k">if</span><span class="o">(</span><span class="n">it</span><span class="o">.</span><span class="na">getName</span><span class="o">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">SUFFIX_VARIABLE</span><span class="o">)</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="n">println</span><span class="o">(</span><span class="s2">"Updating default value of '${SUFFIX_VARIABLE}' variable to '${NEW_SUFFIX}'"</span><span class="o">)</span>
<span class="w"> </span><span class="n">it</span><span class="o">.</span><span class="na">setDefaultValue</span><span class="o">(</span><span class="n">NEW_SUFFIX</span><span class="o">)</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</section>
</section>
</section>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<ul class="nav navbar-nav" style=" float: right;">
<li>
<a href="AutomatedBuildProcess.html" title="Previous Chapter: The Automated Build Process"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm hidden-tablet">« The Automated...</span>
</a>
</li>
<li>
<a href="ReleaseChecklist.html" title="Next Chapter: Release Checklist"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm hidden-tablet">Release Checklist »</span>
</a>
</li>
<li><a href="#">Back to top</a></li>
</ul>
<p>
</p>
</div>
</footer>
</body>
</html>