/
PublisherContext.groovy
1922 lines (1753 loc) · 77.8 KB
/
PublisherContext.groovy
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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package javaposse.jobdsl.dsl.helpers.publisher
import javaposse.jobdsl.dsl.ContextHelper
import javaposse.jobdsl.dsl.ContextType
import javaposse.jobdsl.dsl.DslContext
import javaposse.jobdsl.dsl.Item
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.Preconditions
import javaposse.jobdsl.dsl.RequiresPlugin
import javaposse.jobdsl.dsl.AbstractExtensibleContext
import javaposse.jobdsl.dsl.helpers.common.PublishOverSshContext
import javaposse.jobdsl.dsl.jobs.MatrixJob
import static javaposse.jobdsl.dsl.ContextHelper.toNamedNode
import static javaposse.jobdsl.dsl.Preconditions.checkArgument
import static javaposse.jobdsl.dsl.Preconditions.checkNotNullOrEmpty
import static javaposse.jobdsl.dsl.helpers.common.Threshold.THRESHOLD_COLOR_MAP
import static javaposse.jobdsl.dsl.helpers.common.Threshold.THRESHOLD_COMPLETED_BUILD
import static javaposse.jobdsl.dsl.helpers.common.Threshold.THRESHOLD_ORDINAL_MAP
@ContextType('hudson.tasks.Publisher')
class PublisherContext extends AbstractExtensibleContext {
List<Node> publisherNodes = []
PublisherContext(JobManagement jobManagement, Item item) {
super(jobManagement, item)
}
@Override
protected void addExtensionNode(Node node) {
publisherNodes << node
}
/**
* Sends customizable email notifications.
*
* @since 1.43
*/
@RequiresPlugin(id = 'email-ext', minimumVersion = '2.40.5')
void extendedEmail(@DslContext(ExtendedEmailContext) Closure closure) {
ExtendedEmailContext context = new ExtendedEmailContext()
ContextHelper.executeInContext(closure, context)
if (!context.triggersContext.configuredTriggers) {
context.triggers {
failure()
}
}
Node emailNode = new NodeBuilder().'hudson.plugins.emailext.ExtendedEmailPublisher' {
recipientList(context.recipientList ? context.recipientList.join(', ') : '$DEFAULT_RECIPIENTS')
configuredTriggers(context.triggersContext.configuredTriggers)
contentType(context.contentType)
defaultSubject(context.defaultSubject ?: '')
defaultContent(context.defaultContent ?: '')
attachmentsPattern(context.attachmentPatterns.join(', '))
presendScript(context.preSendScript ?: '')
classpath {
context.additionalGroovyClasspath.each { classpath ->
'hudson.plugins.emailext.GroovyScriptPath' {
path(classpath ?: '')
}
}
}
attachBuildLog(context.attachBuildLog)
compressBuildLog(context.compressBuildLog)
replyTo(context.replyToList ? context.replyToList.join(', ') : '$DEFAULT_REPLYTO')
saveOutput(context.saveToWorkspace)
disabled(context.disabled)
}
ContextHelper.executeConfigureBlock(emailNode, context.configureBlock)
publisherNodes << emailNode
}
/**
* Sends email notifications.
*
* @since 1.17
*/
@RequiresPlugin(id = 'mailer')
void mailer(String recipients, Boolean dontNotifyEveryUnstableBuild = false, Boolean sendToIndividuals = false) {
publisherNodes << new NodeBuilder().'hudson.tasks.Mailer' {
delegate.recipients(recipients)
delegate.dontNotifyEveryUnstableBuild(dontNotifyEveryUnstableBuild)
delegate.sendToIndividuals(sendToIndividuals)
}
}
/**
* Archives artifacts with each build.
*
* @since 1.20
*/
void archiveArtifacts(@DslContext(ArchiveArtifactsContext) Closure artifactsClosure) {
ArchiveArtifactsContext artifactsContext = new ArchiveArtifactsContext(jobManagement)
ContextHelper.executeInContext(artifactsClosure, artifactsContext)
publisherNodes << new NodeBuilder().'hudson.tasks.ArtifactArchiver' {
artifacts(artifactsContext.patterns.join(','))
if (artifactsContext.excludes) {
excludes(artifactsContext.excludes)
}
allowEmptyArchive(artifactsContext.allowEmpty)
defaultExcludes(artifactsContext.defaultExcludes)
delegate.fingerprint(artifactsContext.fingerprint)
onlyIfSuccessful(artifactsContext.onlyIfSuccessful)
}
}
/**
* Archives artifacts with each build.
*/
void archiveArtifacts(String glob, String excludeGlob = null) {
archiveArtifacts {
pattern(glob)
exclude(excludeGlob)
}
}
/**
* Publishes JUnit test result reports.
*
* @since 1.26
*/
@RequiresPlugin(id = 'junit', minimumVersion = '1.10')
void archiveJunit(String glob, @DslContext(ArchiveJUnitContext) Closure junitClosure = null) {
ArchiveJUnitContext junitContext = new ArchiveJUnitContext(jobManagement)
ContextHelper.executeInContext(junitClosure, junitContext)
publisherNodes << new NodeBuilder().'hudson.tasks.junit.JUnitResultArchiver' {
testResults(glob)
keepLongStdio(junitContext.retainLongStdout)
testDataPublishers(junitContext.testDataPublishersContext.testDataPublishers)
allowEmptyResults(junitContext.allowEmptyResults)
healthScaleFactor(junitContext.healthScaleFactor)
}
}
/**
* Publishes reports generated from results of various testing tools.
*
* @since 1.24
*/
@RequiresPlugin(id = 'xunit')
void archiveXUnit(@DslContext(ArchiveXUnitContext) Closure xUnitClosure) {
ArchiveXUnitContext xUnitContext = new ArchiveXUnitContext(jobManagement)
ContextHelper.executeInContext(xUnitClosure, xUnitContext)
publisherNodes << new NodeBuilder().'xunit' {
types {
xUnitContext.resultFiles.each { ArchiveXUnitResultFileContext resultFile ->
"${resultFile.type}" {
pattern resultFile.pattern
skipNoTestFiles resultFile.skipNoTestFiles
failIfNotNew resultFile.failIfNotNew
deleteOutputFiles resultFile.deleteOutputFiles
stopProcessingIfError resultFile.stopProcessingIfError
if (resultFile instanceof ArchiveXUnitCustomToolContext) {
customXSL resultFile.stylesheet
}
}
}
}
thresholds {
'org.jenkinsci.plugins.xunit.threshold.FailedThreshold' {
unstableThreshold xUnitContext.failedThresholdsContext.unstable == null ? ''
: xUnitContext.failedThresholdsContext.unstable
unstableNewThreshold xUnitContext.failedThresholdsContext.unstableNew == null ? ''
: xUnitContext.failedThresholdsContext.unstableNew
failureThreshold xUnitContext.failedThresholdsContext.failure == null ? ''
: xUnitContext.failedThresholdsContext.failure
failureNewThreshold xUnitContext.failedThresholdsContext.failureNew == null ? ''
: xUnitContext.failedThresholdsContext.failureNew
}
'org.jenkinsci.plugins.xunit.threshold.SkippedThreshold' {
unstableThreshold xUnitContext.skippedThresholdsContext.unstable == null ? ''
: xUnitContext.skippedThresholdsContext.unstable
unstableNewThreshold xUnitContext.skippedThresholdsContext.unstableNew == null ? ''
: xUnitContext.skippedThresholdsContext.unstableNew
failureThreshold xUnitContext.skippedThresholdsContext.failure == null ? ''
: xUnitContext.skippedThresholdsContext.failure
failureNewThreshold xUnitContext.skippedThresholdsContext.failureNew == null ? ''
: xUnitContext.skippedThresholdsContext.failureNew
}
}
thresholdMode xUnitContext.thresholdMode.xmlValue
extraConfiguration {
testTimeMargin xUnitContext.timeMargin
}
}
}
/**
* Publishes TestNG test result reports.
*
* @since 1.40
*/
@RequiresPlugin(id = 'testng-plugin', minimumVersion = '1.10')
void archiveTestNG(String glob = '**/testng-results.xml',
@DslContext(ArchiveTestNGContext) Closure testNGClosure = null) {
ArchiveTestNGContext testNGContext = new ArchiveTestNGContext(jobManagement)
ContextHelper.executeInContext(testNGClosure, testNGContext)
publisherNodes << new NodeBuilder().'hudson.plugins.testng.Publisher' {
reportFilenamePattern(glob)
escapeTestDescp(testNGContext.escapeTestDescription)
escapeExceptionMsg(testNGContext.escapeExceptionMessages)
showFailedBuilds(testNGContext.showFailedBuildsInTrendGraph)
unstableOnSkippedTests(testNGContext.markBuildAsUnstableOnSkippedTests)
failureOnFailedTestConfig(testNGContext.markBuildAsFailureOnFailedConfiguration)
}
}
/**
* Publishes Gatling load simulation reports.
*
* @since 1.41
*/
@RequiresPlugin(id = 'gatling', minimumVersion = '1.1.1')
void archiveGatling(@DslContext(ArchiveGatlingContext) Closure gatlingClosure = null) {
ArchiveGatlingContext gatlingContext = new ArchiveGatlingContext(jobManagement)
ContextHelper.executeInContext(gatlingClosure, gatlingContext)
publisherNodes << new NodeBuilder().'io.gatling.jenkins.GatlingPublisher' {
enabled(gatlingContext.enabled)
}
}
/**
* Publishes a JaCoCo coverage report.
*
* @since 1.17
*/
@RequiresPlugin(id = 'jacoco')
void jacocoCodeCoverage(@DslContext(JacocoContext) Closure jacocoClosure = null) {
JacocoContext jacocoContext = new JacocoContext(jobManagement)
ContextHelper.executeInContext(jacocoClosure, jacocoContext)
publisherNodes << new NodeBuilder().'hudson.plugins.jacoco.JacocoPublisher' {
execPattern jacocoContext.execPattern
classPattern jacocoContext.classPattern
sourcePattern jacocoContext.sourcePattern
inclusionPattern jacocoContext.inclusionPattern
exclusionPattern jacocoContext.exclusionPattern
minimumInstructionCoverage jacocoContext.minimumInstructionCoverage
minimumBranchCoverage jacocoContext.minimumBranchCoverage
minimumComplexityCoverage jacocoContext.minimumComplexityCoverage
minimumLineCoverage jacocoContext.minimumLineCoverage
minimumMethodCoverage jacocoContext.minimumMethodCoverage
minimumClassCoverage jacocoContext.minimumClassCoverage
maximumInstructionCoverage jacocoContext.maximumInstructionCoverage
maximumBranchCoverage jacocoContext.maximumBranchCoverage
maximumComplexityCoverage jacocoContext.maximumComplexityCoverage
maximumLineCoverage jacocoContext.maximumLineCoverage
maximumMethodCoverage jacocoContext.maximumMethodCoverage
maximumClassCoverage jacocoContext.maximumClassCoverage
if (jacocoContext.changeBuildStatus != null) {
changeBuildStatus jacocoContext.changeBuildStatus
}
}
}
/**
* Plots data across builds.
*
* @since 1.31
*/
@RequiresPlugin(id = 'plot', minimumVersion = '1.9')
void plotBuildData(@DslContext(PlotsContext) Closure plotsClosure) {
PlotsContext plotsContext = new PlotsContext(jobManagement)
ContextHelper.executeInContext(plotsClosure, plotsContext)
publisherNodes << new NodeBuilder().'hudson.plugins.plot.PlotPublisher' {
plots {
plotsContext.plots.each { PlotContext plot ->
'hudson.plugins.plot.Plot' {
title(plot.title ?: '')
yaxis(plot.yAxis ?: '')
series {
plot.dataSeriesList.each { PlotSeriesContext data ->
"hudson.plugins.plot.${data.seriesType}" {
file(data.fileName)
fileType(data.fileType)
if (data instanceof PlotPropertiesSeriesContext) {
label(data.label ?: '')
}
if (data instanceof PlotCSVSeriesContext) {
label()
inclusionFlag(data.inclusionFlag)
exclusionValues(data.exclusionSet.join(','))
switch (data.inclusionFlag) {
case ['INCLUDE_BY_STRING', 'EXCLUDE_BY_STRING']:
strExclusionSet {
data.exclusionSet.each { String exclusion ->
string(exclusion)
}
}
break
case ['INCLUDE_BY_COLUMN', 'EXCLUDE_BY_COLUMN']:
colExclusionSet {
data.exclusionSet.each { String exclusion ->
'int'(exclusion)
}
}
break
}
url(data.url ?: '')
displayTableFlag(data.showTable)
}
if (data instanceof PlotXMLSeriesContext) {
label()
xpathString(data.xpath ?: '')
url(data.url ?: '')
nodeTypeString(data.nodeType)
}
}
}
}
group(plot.group)
numBuilds(plot.numberOfBuilds ?: '')
csvFileName(plot.dataStore)
csvLastModification(0)
style(plot.style)
useDescr(plot.useDescriptions)
keepRecords(plot.keepRecords)
exclZero(plot.excludeZero)
logarithmic(plot.logarithmic)
if (jobManagement.isMinimumPluginVersionInstalled('plot', '1.10')) {
yaxisMinimum(plot.yAxisMinimum ?: '')
yaxisMaximum(plot.yAxisMaximum ?: '')
}
}
}
}
}
}
/**
* Publishes HTML reports.
*/
@RequiresPlugin(id = 'htmlpublisher', minimumVersion = '1.5')
void publishHtml(@DslContext(HtmlReportContext) Closure htmlReportContext) {
jobManagement.logPluginDeprecationWarning('htmlpublisher', '1.13')
HtmlReportContext reportContext = new HtmlReportContext(jobManagement)
ContextHelper.executeInContext(htmlReportContext, reportContext)
publisherNodes << new NodeBuilder().'htmlpublisher.HtmlPublisher' {
reportTargets {
reportContext.targets.each { HtmlReportTargetContext target ->
'htmlpublisher.HtmlPublisherTarget' {
reportName(target.reportName ?: '')
reportDir(target.reportDir)
reportFiles(target.reportFiles ?: '')
if (jobManagement.isMinimumPluginVersionInstalled('htmlpublisher', '1.13')) {
reportTitles(target.reportTitles ?: '')
}
keepAll(target.keepAll)
allowMissing(target.allowMissing)
alwaysLinkToLastBuild(target.alwaysLinkToLastBuild)
}
}
}
}
}
/**
* Sends notifications to Jabber.
*/
@RequiresPlugin(id = 'jabber', minimumVersion = '1.35')
void publishJabber(String targets, @DslContext(JabberContext) Closure jabberClosure = null) {
JabberContext jabberContext = new JabberContext(jobManagement)
ContextHelper.executeInContext(jabberClosure, jabberContext)
publisherNodes << new NodeBuilder().'hudson.plugins.jabber.im.transport.JabberPublisher' {
delegate.targets {
targets.split().each { target ->
if (target.startsWith('*') || target.contains('@conference.')) {
'hudson.plugins.im.GroupChatIMMessageTarget' {
name(target.startsWith('*') ? target[1..-1] : target)
notificationOnly(false)
}
} else {
'hudson.plugins.im.DefaultIMMessageTarget' {
value(target)
}
}
}
}
strategy(jabberContext.strategyName)
notifyOnBuildStart(jabberContext.notifyOnBuildStart)
notifySuspects(jabberContext.notifySuspects)
notifyCulprits(jabberContext.notifyCulprits)
notifyFixers(jabberContext.notifyFixers)
notifyUpstreamCommitters(jabberContext.notifyUpstreamCommitters)
buildToChatNotifier(
class: "hudson.plugins.im.build_notify.${jabberContext.channelNotificationName}BuildToChatNotifier"
)
matrixMultiplier('ONLY_CONFIGURATIONS')
}
}
/**
* Uploads artifacts to the remote sites using the SFTP (SSH) protocol. The site is specified in the global Jenkins
* configuration.
*/
@RequiresPlugin(id = 'scp')
void publishScp(String site, @DslContext(ScpContext) Closure scpClosure) {
ScpContext scpContext = new ScpContext()
ContextHelper.executeInContext(scpClosure, scpContext)
// Validate values
checkArgument(!scpContext.entries.empty, 'Scp publish requires at least one entry')
publisherNodes << new NodeBuilder().'be.certipost.hudson.plugin.SCPRepositoryPublisher' {
siteName site
entries {
scpContext.entries.each { ScpContext.ScpEntry entry ->
'be.certipost.hudson.plugin.Entry' {
filePath entry.destination
sourceFile entry.source
keepHierarchy entry.keepHierarchy ? 'true' : 'false'
}
}
}
}
}
/**
* Archives files for Clone Workspace SCM source.
*/
@RequiresPlugin(id = 'clone-workspace-scm')
void publishCloneWorkspace(String workspaceGlob, @DslContext(CloneWorkspaceContext) Closure cloneWorkspaceClosure) {
publishCloneWorkspace(workspaceGlob, '', 'Any', 'TAR', false, cloneWorkspaceClosure)
}
/**
* Archives files for Clone Workspace SCM source.
*/
@RequiresPlugin(id = 'clone-workspace-scm')
void publishCloneWorkspace(String workspaceGlob, String workspaceExcludeGlob,
@DslContext(CloneWorkspaceContext) Closure cloneWorkspaceClosure) {
publishCloneWorkspace(workspaceGlob, workspaceExcludeGlob, 'Any', 'TAR', false, cloneWorkspaceClosure)
}
/**
* Archives files for Clone Workspace SCM source.
*/
@RequiresPlugin(id = 'clone-workspace-scm')
void publishCloneWorkspace(String workspaceGlob, String workspaceExcludeGlob, String criteria, String archiveMethod,
@DslContext(CloneWorkspaceContext) Closure cloneWorkspaceClosure) {
publishCloneWorkspace(
workspaceGlob, workspaceExcludeGlob, criteria, archiveMethod, false, cloneWorkspaceClosure
)
}
/**
* Archives files for Clone Workspace SCM source.
*/
@RequiresPlugin(id = 'clone-workspace-scm')
void publishCloneWorkspace(String workspaceGlob, String workspaceExcludeGlob = '', String criteria = 'Any',
String archiveMethod = 'TAR', boolean overrideDefaultExcludes = false,
@DslContext(CloneWorkspaceContext) Closure cloneWorkspaceClosure = null) {
CloneWorkspaceContext cloneWorkspaceContext = new CloneWorkspaceContext()
cloneWorkspaceContext.criteria = criteria ?: 'Any'
cloneWorkspaceContext.archiveMethod = archiveMethod ?: 'TAR'
cloneWorkspaceContext.workspaceExcludeGlob = workspaceExcludeGlob ?: ''
cloneWorkspaceContext.overrideDefaultExcludes = overrideDefaultExcludes ?: false
ContextHelper.executeInContext(cloneWorkspaceClosure, cloneWorkspaceContext)
// Validate values
checkArgument(
validCloneWorkspaceCriteria.contains(cloneWorkspaceContext.criteria),
"Clone Workspace Criteria needs to be one of these values: ${validCloneWorkspaceCriteria.join(',')}"
)
checkArgument(
validCloneWorkspaceArchiveMethods.contains(cloneWorkspaceContext.archiveMethod),
'Clone Workspace Archive Method needs to be one of these values: ' +
validCloneWorkspaceArchiveMethods.join(',')
)
publisherNodes << new NodeBuilder().'hudson.plugins.cloneworkspace.CloneWorkspacePublisher' {
delegate.workspaceGlob(workspaceGlob)
delegate.workspaceExcludeGlob(cloneWorkspaceContext.workspaceExcludeGlob)
delegate.criteria(cloneWorkspaceContext.criteria)
delegate.archiveMethod(cloneWorkspaceContext.archiveMethod)
delegate.overrideDefaultExcludes(cloneWorkspaceContext.overrideDefaultExcludes)
}
}
static List<String> validCloneWorkspaceCriteria = ['Any', 'Not Failed', 'Successful']
Set<String> validCloneWorkspaceArchiveMethods = ['TAR', 'ZIP']
/**
* Triggers builds on other projects.
*
* The {@code threshold} must be one of {@code 'SUCCESS'}, {@code 'UNSTABLE'} or {@code 'FAILURE'}.
*/
void downstream(String projectName, String thresholdName = 'SUCCESS') {
checkArgument(
THRESHOLD_COLOR_MAP.containsKey(thresholdName),
"thresholdName must be one of these values ${THRESHOLD_COLOR_MAP.keySet().join(',')}"
)
publisherNodes << new NodeBuilder().'hudson.tasks.BuildTrigger' {
childProjects projectName
threshold {
delegate.createNode('name', thresholdName)
ordinal THRESHOLD_ORDINAL_MAP[thresholdName]
color THRESHOLD_COLOR_MAP[thresholdName]
}
}
}
/**
* Triggers builds on other projects.
*
* The {@code threshold} must be one of {@code 'SUCCESS'}, {@code 'UNSTABLE'} or {@code 'FAILURE'}.
*
* @since 1.39
*/
void downstream(List<String> projectName, String thresholdName = 'SUCCESS') {
downstream(projectName.join(', '), thresholdName)
}
/**
* Triggers parameterized builds on other projects.
*/
@RequiresPlugin(id = 'parameterized-trigger', minimumVersion = '2.26')
void downstreamParameterized(@DslContext(DownstreamContext) Closure downstreamClosure) {
DownstreamContext downstreamContext = new DownstreamContext(jobManagement, item)
ContextHelper.executeInContext(downstreamClosure, downstreamContext)
publisherNodes << new NodeBuilder().'hudson.plugins.parameterizedtrigger.BuildTrigger' {
configs(downstreamContext.configs)
}
}
/**
* Generates reports from static code violations detectors.
*/
@RequiresPlugin(id = 'violations')
void violations(@DslContext(ViolationsContext) Closure violationsClosure = null) {
violations(100, violationsClosure)
}
/**
* Generates reports from static code violations detectors.
*/
@RequiresPlugin(id = 'violations')
void violations(int perFileDisplayLimit, @DslContext(ViolationsContext) Closure violationsClosure = null) {
ViolationsContext violationsContext = new ViolationsContext()
violationsContext.perFileDisplayLimit = perFileDisplayLimit
ContextHelper.executeInContext(violationsClosure, violationsContext)
publisherNodes << new NodeBuilder().'hudson.plugins.violations.ViolationsPublisher' {
config {
suppressions(class: 'tree-set') {
'no-comparator'()
}
typeConfigs {
'no-comparator'()
violationsContext.entries.each { String key, ViolationsContext.ViolationsEntry violationsEntry ->
entry {
string(key)
'hudson.plugins.violations.TypeConfig' {
type(key)
// These values are protected from ever being null or empty.
min(violationsEntry.min.toString())
max(violationsEntry.max.toString())
unstable(violationsEntry.unstable.toString())
usePattern(violationsEntry.pattern ? 'true' : 'false')
pattern(violationsEntry.pattern ?: '')
}
}
}
}
limit(violationsContext.perFileDisplayLimit.toString())
sourcePathPattern(violationsContext.sourcePathPattern ?: '')
fauxProjectPath(violationsContext.fauxProjectPath ?: '')
encoding(violationsContext.sourceEncoding ?: 'default')
}
}
}
/**
* Displays a picture of Chuck Norris (instead of Jenkins the butler) and a random Chuck Norris 'The Programmer'
* fact on each build page.
*/
@RequiresPlugin(id = 'chucknorris')
void chucknorris() {
publisherNodes << new NodeBuilder().'hudson.plugins.chucknorris.CordellWalkerRecorder' {
'factGenerator' ''
}
}
/**
* Sends notifications to IRC.
*
* @since 1.15
*/
@RequiresPlugin(id = 'ircbot', minimumVersion = '2.27')
void irc(@DslContext(IrcContext) Closure ircClosure) {
IrcContext ircContext = new IrcContext(jobManagement)
ContextHelper.executeInContext(ircClosure, ircContext)
publisherNodes << new NodeBuilder().'hudson.plugins.ircbot.IrcPublisher' {
targets {
ircContext.channels.each { IrcContext.IrcPublisherChannel channel ->
'hudson.plugins.im.GroupChatIMMessageTarget' {
delegate.createNode('name', channel.name)
password(channel.password)
notificationOnly(channel.notificationOnly)
}
}
}
strategy(ircContext.strategy)
notifyOnBuildStart(ircContext.notifyOnBuildStarts)
notifySuspects(ircContext.notifyScmCommitters)
notifyCulprits(ircContext.notifyScmCulprits)
notifyFixers(ircContext.notifyScmFixers)
notifyUpstreamCommitters(ircContext.notifyUpstreamCommitters)
buildToChatNotifier(
class: "hudson.plugins.im.build_notify.${ircContext.notificationMessage}BuildToChatNotifier"
)
}
}
/**
* Publishes a Cobertura coverage report.
*
* @since 1.16
*/
@RequiresPlugin(id = 'cobertura')
void cobertura(String reportFile, @DslContext(CoberturaContext) Closure coberturaClosure = null) {
CoberturaContext coberturaContext = new CoberturaContext()
ContextHelper.executeInContext(coberturaClosure, coberturaContext)
publisherNodes << new NodeBuilder().'hudson.plugins.cobertura.CoberturaPublisher' {
coberturaReportFile(reportFile)
onlyStable(coberturaContext.onlyStable)
failUnhealthy(coberturaContext.failUnhealthy)
failUnstable(coberturaContext.failUnstable)
autoUpdateHealth(coberturaContext.autoUpdateHealth)
autoUpdateStability(coberturaContext.autoUpdateStability)
zoomCoverageChart(coberturaContext.zoomCoverageChart)
failNoReports(coberturaContext.failNoReports)
['healthyTarget', 'unhealthyTarget', 'failingTarget'].each { targetName ->
"$targetName" {
targets(class: 'enum-map', 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric') {
coberturaContext.targets.values().each { target ->
entry {
'hudson.plugins.cobertura.targets.CoverageMetric' target.targetType
'int' target."$targetName"
}
}
}
}
}
sourceEncoding(coberturaContext.sourceEncoding)
}
}
/**
* Allows to claim unsuccessful builds.
*
* @since 1.17
*/
@RequiresPlugin(id = 'claim')
void allowBrokenBuildClaiming() {
publisherNodes << new NodeBuilder().'hudson.plugins.claim.ClaimPublisher'()
}
/**
* Activates fingerprinting for the build.
*
* @since 1.17
*/
void fingerprint(String targets, boolean recordBuildArtifacts = false) {
publisherNodes << new NodeBuilder().'hudson.tasks.Fingerprinter' {
delegate.targets(targets ?: '')
delegate.recordBuildArtifacts(recordBuildArtifacts)
}
}
/**
* Automatically sets a description for the build after it has completed.
*
* @since 1.17
*/
@RequiresPlugin(id = 'description-setter')
@SuppressWarnings('UnnecessarySetter') // false positive for setForMatrix
void buildDescription(String regularExpression, String description = '', String regularExpressionForFailed = '',
String descriptionForFailed = '', boolean multiConfigurationBuild = false) {
publisherNodes << new NodeBuilder().'hudson.plugins.descriptionsetter.DescriptionSetterPublisher' {
regexp(regularExpression)
regexpForFailed(regularExpressionForFailed)
if (description) {
delegate.description(description)
}
if (descriptionForFailed) {
delegate.descriptionForFailed(descriptionForFailed)
}
setForMatrix(multiConfigurationBuild)
}
}
/**
* Searches for keywords in files or the console log and uses that to downgrade a build to be unstable or a failure.
*
* @since 1.19
*/
@RequiresPlugin(id = 'text-finder')
void textFinder(String regularExpression, String fileSet = '', boolean alsoCheckConsoleOutput = false,
boolean succeedIfFound = false, Object unstableIfFound = false) {
publisherNodes << new NodeBuilder().'hudson.plugins.textfinder.TextFinderPublisher' {
if (fileSet) {
delegate.fileSet(fileSet)
}
delegate.regexp(regularExpression)
delegate.alsoCheckConsoleOutput(alsoCheckConsoleOutput)
delegate.succeedIfFound(succeedIfFound)
delegate.unstableIfFound(unstableIfFound)
}
}
/**
* Searches for a regular expression in the console log and, if matched, executes a script.
*
* @since 1.19
*/
@RequiresPlugin(id = 'postbuild-task')
void postBuildTask(@DslContext(PostBuildTaskContext) Closure postBuildClosure) {
PostBuildTaskContext postBuildContext = new PostBuildTaskContext()
ContextHelper.executeInContext(postBuildClosure, postBuildContext)
publisherNodes << new NodeBuilder().'hudson.plugins.postbuildtask.PostbuildTask' {
tasks {
postBuildContext.tasks.each { PostBuildTaskContext.PostBuildTask task ->
'hudson.plugins.postbuildtask.TaskProperties' {
logTexts {
'hudson.plugins.postbuildtask.LogProperties' {
logText(task.logText)
operator(task.operator)
}
}
EscalateStatus(task.escalateStatus)
RunIfJobSuccessful(task.runIfJobSuccessful)
script(task.script)
}
}
}
}
}
/**
* Aggregates downstream test results.
*
* @since 1.19
*/
void aggregateDownstreamTestResults(String jobs = null, boolean includeFailedBuilds = false) {
publisherNodes << new NodeBuilder().'hudson.tasks.test.AggregatedTestResultPublisher' {
if (jobs) {
delegate.jobs(jobs)
}
delegate.includeFailedBuilds(includeFailedBuilds)
}
}
static enum Behavior {
DoNothing(0),
MarkUnstable(1),
MarkFailed(2)
final int value
Behavior(int value) {
this.value = value
}
}
/**
* Executes Groovy scripts after a build.
*
* @since 1.19
*/
@RequiresPlugin(id = 'groovy-postbuild', minimumVersion = '2.2')
void groovyPostBuild(String script, Behavior behavior = Behavior.DoNothing) {
groovyPostBuild {
delegate.script(script)
delegate.behavior(behavior)
}
}
/**
* Executes Groovy scripts after a build.
*
* @since 1.37
*/
@RequiresPlugin(id = 'groovy-postbuild', minimumVersion = '2.2')
void groovyPostBuild(@DslContext(GroovyPostbuildContext) Closure groovyPostbuildClosure) {
GroovyPostbuildContext groovyPostbuildContext = new GroovyPostbuildContext(jobManagement)
ContextHelper.executeInContext(groovyPostbuildClosure, groovyPostbuildContext)
publisherNodes << new NodeBuilder().'org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder' {
script {
script(groovyPostbuildContext.script ?: '')
sandbox(groovyPostbuildContext.sandbox)
if (groovyPostbuildContext.classpath) {
classpath {
groovyPostbuildContext.classpath.each { value ->
entry {
url(value)
}
}
}
}
}
behavior(groovyPostbuildContext.behavior.value)
}
}
/**
* Archives Javadoc artifacts.
*
* @since 1.19
*/
@RequiresPlugin(id = 'javadoc')
void archiveJavadoc(@DslContext(JavadocContext) Closure javadocClosure = null) {
JavadocContext javadocContext = new JavadocContext()
ContextHelper.executeInContext(javadocClosure, javadocContext)
publisherNodes << new NodeBuilder().'hudson.tasks.JavadocArchiver' {
javadocDir javadocContext.javadocDir
keepAll javadocContext.keepAll
}
}
/**
* Marks files or directories outside of Jenkins as related to a build.
*
* @since 1.20
*/
@RequiresPlugin(id = 'associated-files')
void associatedFiles(String files = null) {
publisherNodes << new NodeBuilder().'org.jenkinsci.plugins.associatedfiles.AssociatedFilesPublisher' {
delegate.associatedFiles(files)
}
}
/**
* Publishes an Emma coverage report.
*
* @since 1.20
*/
@RequiresPlugin(id = 'emma')
void emma(String fileSet = '', @DslContext(EmmaContext) Closure emmaClosure = null) {
EmmaContext emmaContext = new EmmaContext()
ContextHelper.executeInContext(emmaClosure, emmaContext)
publisherNodes << new NodeBuilder().'hudson.plugins.emma.EmmaPublisher' {
includes(fileSet)
healthReports {
minClass(emmaContext.classRange.from)
maxClass(emmaContext.classRange.to)
minMethod(emmaContext.methodRange.from)
maxMethod(emmaContext.methodRange.to)
minBlock(emmaContext.blockRange.from)
maxBlock(emmaContext.blockRange.to)
minLine(emmaContext.lineRange.from)
maxLine(emmaContext.lineRange.to)
minCondition(emmaContext.conditionRange.from)
maxCondition(emmaContext.conditionRange.to)
}
}
}
/**
* Publishes Robot Framework test reports.
*
* @since 1.21
*/
@RequiresPlugin(id = 'robot', minimumVersion = '1.4.3')
void publishRobotFrameworkReports(@DslContext(RobotFrameworkContext) Closure robotClosure = null) {
RobotFrameworkContext context = new RobotFrameworkContext(jobManagement)
ContextHelper.executeInContext(robotClosure, context)
publisherNodes << new NodeBuilder().'hudson.plugins.robot.RobotPublisher' {
passThreshold(context.passThreshold)
unstableThreshold(context.unstableThreshold)
outputPath(context.outputPath)
onlyCritical(context.onlyCritical)
reportFileName(context.reportFileName)
logFileName(context.logFileName)
outputFileName(context.outputFileName)
disableArchiveOutput(context.disableArchiveOutput)
otherFiles {
context.otherFiles.each { String file ->
string(file)
}
}
}
}
/**
* Adds a manual triggers for jobs that require intervention prior to execution.
*
* @since 1.21
*/
@RequiresPlugin(id = 'build-pipeline-plugin')
void buildPipelineTrigger(String downstreamProjectNames, @DslContext(BuildPipelineContext) Closure closure = null) {
BuildPipelineContext buildPipelineContext = new BuildPipelineContext(jobManagement, item)
ContextHelper.executeInContext(closure, buildPipelineContext)
NodeBuilder nodeBuilder = new NodeBuilder()
publisherNodes << nodeBuilder.'au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger' {
delegate.downstreamProjectNames(downstreamProjectNames ?: '')
configs(buildPipelineContext.parameterNodes)
}
}
/**
* Create commit status notifications on the commits based on the outcome of the build.
*
* @since 1.21
*/
@RequiresPlugin(id = 'github')
void githubCommitNotifier() {
publisherNodes << new NodeBuilder().'com.cloudbees.jenkins.GitHubCommitNotifier'()
}
/**
* Pushes tags or branches to a Git repository.
*
* @since 1.22
*/
@RequiresPlugin(id = 'git', minimumVersion = '2.5.3')
void git(@DslContext(GitPublisherContext) Closure gitPublisherClosure) {
GitPublisherContext context = new GitPublisherContext(jobManagement)
ContextHelper.executeInContext(gitPublisherClosure, context)
publisherNodes << new NodeBuilder().'hudson.plugins.git.GitPublisher' {
configVersion(2)
pushMerge(context.pushMerge)
pushOnlyIfSuccess(context.pushOnlyIfSuccess)
forcePush(context.forcePush)
tagsToPush(context.tags)
notesToPush(context.notes)
branchesToPush(context.branches)
}
}
/**
* Sends build notification to Flowdock.
*
* For security reasons, do not use a hard-coded token. See
* <a href="https://github.com/jenkinsci/job-dsl-plugin/wiki/Handling-Credentials">Handling Credentials</a> for
* details about handling credentials in DSL scripts.
*
* @since 1.23
*/
@RequiresPlugin(id = 'jenkins-flowdock-plugin')
void flowdock(String token, @DslContext(FlowdockPublisherContext) Closure flowdockPublisherClosure = null) {
FlowdockPublisherContext context = new FlowdockPublisherContext()
ContextHelper.executeInContext(flowdockPublisherClosure, context)
publisherNodes << new NodeBuilder().'com.flowdock.jenkins.FlowdockNotifier' {
flowToken(token)
notificationTags(context.notificationTags.join(','))
chatNotification(context.chat)
notifyMap {
entry {
'com.flowdock.jenkins.BuildResult'('ABORTED')
'boolean'(context.aborted)
}
entry {
'com.flowdock.jenkins.BuildResult'('SUCCESS')
'boolean'(context.success)
}
entry {
'com.flowdock.jenkins.BuildResult'('FIXED')
'boolean'(context.fixed)
}
entry {
'com.flowdock.jenkins.BuildResult'('UNSTABLE')
'boolean'(context.unstable)
}
entry {
'com.flowdock.jenkins.BuildResult'('FAILURE')
'boolean'(context.failure)
}
entry {
'com.flowdock.jenkins.BuildResult'('NOT_BUILT')
'boolean'(context.notBuilt)
}
}
notifySuccess(context.success)
notifyFailure(context.failure)