jenkins_pipeline_builder 0.10.16 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +8 -8
  2. data/.rubocop.yml +4 -4
  3. data/lib/jenkins_pipeline_builder.rb +5 -0
  4. data/lib/jenkins_pipeline_builder/compiler.rb +27 -24
  5. data/lib/jenkins_pipeline_builder/extension_dsl.rb +1 -0
  6. data/lib/jenkins_pipeline_builder/extension_set.rb +8 -8
  7. data/lib/jenkins_pipeline_builder/extensions.rb +12 -24
  8. data/lib/jenkins_pipeline_builder/extensions/builders.rb +36 -27
  9. data/lib/jenkins_pipeline_builder/extensions/helpers/builders/blocking_downstream_helper.rb +18 -0
  10. data/lib/jenkins_pipeline_builder/extensions/helpers/builders/maven3_helper.rb +11 -0
  11. data/lib/jenkins_pipeline_builder/extensions/helpers/extension_helper.rb +26 -0
  12. data/lib/jenkins_pipeline_builder/extensions/helpers/job_attributes/parameters_helper.rb +18 -0
  13. data/lib/jenkins_pipeline_builder/extensions/helpers/publishers/cobertura_report_helper.rb +40 -0
  14. data/lib/jenkins_pipeline_builder/extensions/helpers/publishers/email_ext_helper.rb +148 -0
  15. data/lib/jenkins_pipeline_builder/extensions/helpers/triggers/upstream_helper.rb +21 -0
  16. data/lib/jenkins_pipeline_builder/extensions/job_attributes.rb +1 -15
  17. data/lib/jenkins_pipeline_builder/extensions/publishers.rb +263 -6
  18. data/lib/jenkins_pipeline_builder/extensions/triggers.rb +3 -17
  19. data/lib/jenkins_pipeline_builder/extensions/wrappers.rb +3 -3
  20. data/lib/jenkins_pipeline_builder/generator.rb +10 -11
  21. data/lib/jenkins_pipeline_builder/job.rb +29 -25
  22. data/lib/jenkins_pipeline_builder/job_collection.rb +31 -21
  23. data/lib/jenkins_pipeline_builder/module_registry.rb +5 -1
  24. data/lib/jenkins_pipeline_builder/project.rb +28 -0
  25. data/lib/jenkins_pipeline_builder/pull_request_generator.rb +8 -8
  26. data/lib/jenkins_pipeline_builder/version.rb +1 -1
  27. data/spec/lib/jenkins_pipeline_builder/extension_dsl_spec.rb +43 -0
  28. data/spec/lib/jenkins_pipeline_builder/extension_set_spec.rb +110 -0
  29. data/spec/lib/jenkins_pipeline_builder/extensions/builders_spec.rb +56 -0
  30. data/spec/lib/jenkins_pipeline_builder/extensions/job_attributes_spec.rb +85 -0
  31. data/spec/lib/jenkins_pipeline_builder/extensions/publishers_spec.rb +81 -9
  32. data/spec/lib/jenkins_pipeline_builder/extensions/registered_spec.rb +134 -0
  33. data/spec/lib/jenkins_pipeline_builder/extensions/triggers_spec.rb +88 -0
  34. data/spec/lib/jenkins_pipeline_builder/extensions_spec.rb +0 -97
  35. data/spec/lib/jenkins_pipeline_builder/fixtures/job_collection/extensions/extension.rb +11 -0
  36. data/spec/lib/jenkins_pipeline_builder/fixtures/job_collection/extensions/helpers/my_test_thing_helper.rb +5 -0
  37. data/spec/lib/jenkins_pipeline_builder/job_collection_spec.rb +46 -0
  38. data/spec/lib/jenkins_pipeline_builder/module_registry_spec.rb +1 -110
  39. data/spec/lib/jenkins_pipeline_builder/spec_helper.rb +12 -0
  40. metadata +24 -2
@@ -0,0 +1,148 @@
1
+ class EmailExtHelper < ExtensionHelper
2
+ # rubocop:disable Metrics/MethodLength
3
+ def trigger_defaults
4
+ {
5
+ first_failure: {
6
+ name: 'FirstFailureTrigger',
7
+ send_to_recipient_list: true,
8
+ send_to_developers: true,
9
+ send_to_requester: false,
10
+ include_culprits: false
11
+ },
12
+ first_unstable: {
13
+ name: 'FirstUnstableTrigger',
14
+ send_to_recipient_list: false,
15
+ send_to_developers: true,
16
+ send_to_requester: false,
17
+ include_culprits: false
18
+ },
19
+ second_failure: {
20
+ name: 'SecondFailureTrigger',
21
+ send_to_recipient_list: true,
22
+ send_to_developers: true,
23
+ send_to_requester: false,
24
+ include_culprits: false
25
+ },
26
+ aborted: {
27
+ name: 'AbortedTrigger',
28
+ send_to_recipient_list: true,
29
+ send_to_developers: true,
30
+ send_to_requester: false,
31
+ include_culprits: false
32
+ },
33
+ always: {
34
+ name: 'AlwaysTrigger',
35
+ send_to_recipient_list: true,
36
+ send_to_developers: true,
37
+ send_to_requester: false,
38
+ include_culprits: false
39
+ },
40
+ before_build: {
41
+ name: 'PreBuildTrigger',
42
+ send_to_recipient_list: true,
43
+ send_to_developers: false,
44
+ send_to_requester: false,
45
+ include_culprits: false
46
+ },
47
+ building: {
48
+ name: 'BuildingTrigger',
49
+ send_to_recipient_list: true,
50
+ send_to_developers: true,
51
+ send_to_requester: false,
52
+ include_culprits: false
53
+ },
54
+ failure: {
55
+ name: 'FailureTrigger',
56
+ send_to_recipient_list: false,
57
+ send_to_developers: true,
58
+ send_to_requester: false,
59
+ include_culprits: false
60
+ },
61
+ fixed: {
62
+ name: 'FixedTrigger',
63
+ send_to_recipient_list: true,
64
+ send_to_developers: true,
65
+ send_to_requester: false,
66
+ include_culprits: false
67
+ },
68
+ fixed_unhealthy: {
69
+ name: 'FixedUnhealthyTrigger',
70
+ send_to_recipient_list: true,
71
+ send_to_developers: true,
72
+ send_to_requester: false,
73
+ include_culprits: false
74
+ },
75
+ improvement: {
76
+ name: 'ImprovementTrigger',
77
+ send_to_recipient_list: true,
78
+ send_to_developers: true,
79
+ send_to_requester: false,
80
+ include_culprits: false
81
+ },
82
+ not_built: {
83
+ name: 'NotBuiltTrigger',
84
+ send_to_recipient_list: true,
85
+ send_to_developers: true,
86
+ send_to_requester: false,
87
+ include_culprits: false
88
+ },
89
+ prebuild_script: {
90
+ name: 'PreBuildScriptTrigger',
91
+ send_to_recipient_list: false,
92
+ send_to_developers: false,
93
+ send_to_requester: false,
94
+ include_culprits: false
95
+ },
96
+ regression: {
97
+ name: 'RegressionTrigger',
98
+ send_to_recipient_list: true,
99
+ send_to_developers: true,
100
+ send_to_requester: false,
101
+ include_culprits: false
102
+ },
103
+ script: {
104
+ name: 'ScriptTrigger',
105
+ send_to_recipient_list: true,
106
+ send_to_developers: false,
107
+ send_to_requester: false,
108
+ include_culprits: false
109
+ },
110
+ status_changed: {
111
+ name: 'StatusChangedTrigger',
112
+ send_to_recipient_list: false,
113
+ send_to_developers: true,
114
+ send_to_requester: false,
115
+ include_culprits: false
116
+ },
117
+ still_failing: {
118
+ name: 'StillFailingTrigger',
119
+ send_to_recipient_list: false,
120
+ send_to_developers: true,
121
+ send_to_requester: false,
122
+ include_culprits: false
123
+ },
124
+ still_unstable: {
125
+ name: 'StillUnstableTrigger',
126
+ send_to_recipient_list: false,
127
+ send_to_developers: true,
128
+ send_to_requester: false,
129
+ include_culprits: false
130
+ },
131
+ success: {
132
+ name: 'SuccessTrigger',
133
+ send_to_recipient_list: false,
134
+ send_to_developers: true,
135
+ send_to_requester: false,
136
+ include_culprits: false
137
+ },
138
+ unstable: {
139
+ name: 'UnstableTrigger',
140
+ send_to_recipient_list: false,
141
+ send_to_developers: true,
142
+ send_to_requester: false,
143
+ include_culprits: false
144
+ }
145
+ }
146
+ end
147
+ # rubocop:enable Metrics/MethodLength
148
+ end
@@ -0,0 +1,21 @@
1
+ class UpstreamHelper < ExtensionHelper
2
+ attr_reader :color, :name, :ordinal
3
+ def initialize(params, builder)
4
+ super params, builder
5
+
6
+ case params[:status]
7
+ when 'unstable'
8
+ @name = 'UNSTABLE'
9
+ @ordinal = '1'
10
+ @color = 'yellow'
11
+ when 'failed'
12
+ @name = 'FAILURE'
13
+ @ordinal = '2'
14
+ @color = 'RED'
15
+ else
16
+ @name = 'SUCCESS'
17
+ @ordinal = '0'
18
+ @color = 'BLUE'
19
+ end
20
+ end
21
+ end
@@ -238,22 +238,8 @@ job_attribute do
238
238
  send('hudson.model.ParametersDefinitionProperty') do
239
239
  parameterDefinitions do
240
240
  params.each do |param|
241
- case param[:type]
242
- when 'string'
243
- paramType = 'hudson.model.StringParameterDefinition'
244
- when 'bool'
245
- paramType = 'hudson.model.BooleanParameterDefinition'
246
- when 'text'
247
- paramType = 'hudson.model.TextParameterDefinition'
248
- when 'password'
249
- paramType = 'hudson.model.PasswordParameterDefinition'
250
- when 'choice'
251
- paramType = 'hudson.model.ChoiceParameterDefinition'
252
- else
253
- paramType = 'hudson.model.StringParameterDefinition'
254
- end
255
241
 
256
- send(paramType) do
242
+ send(params.param_type param) do
257
243
  name param[:name]
258
244
  description param[:description]
259
245
  defaultValue param[:default]
@@ -80,14 +80,35 @@ publisher do
80
80
  jenkins_name 'HipChat Notifications'
81
81
  announced false
82
82
 
83
- xml do |params|
84
- params = {} if params == true
85
- send('jenkins.plugins.hipchat.HipChatNotifier') do
86
- jenkinsUrl params[:jenkinsUrl] || ''
87
- authToken params[:authToken] || ''
88
- room params[:room] || ''
83
+ version '0' do
84
+ xml do |params|
85
+ params = {} if params == true
86
+ send('jenkins.plugins.hipchat.HipChatNotifier') do
87
+ jenkinsUrl params[:jenkinsUrl] || ''
88
+ authToken params[:authToken] || ''
89
+ room params[:room] || ''
90
+ end
91
+ end
92
+ end
93
+
94
+ version '0.1.9' do
95
+ xml do |params|
96
+ send('jenkins.plugins.hipchat.HipChatNotifier') do
97
+ token params[:token] || params[:authToken] || ''
98
+ room params[:room] || ''
99
+ startNotification params[:start_notify] || false
100
+ notifySuccess params[:success_notify] || false
101
+ notifyAborted params[:aborted_notify] || false
102
+ notifyNotBuilt params[:notbuilt_notify] || false
103
+ notifyUnstable params[:unstable_notify] || false
104
+ notifyFailure params[:failure_notify] || false
105
+ notifyBackToNormal params[:normal_notify] || false
106
+ startJobMessage params[:start_message] || ''
107
+ completeJobMessage params[:complete_message] || ''
108
+ end
89
109
  end
90
110
  end
111
+
91
112
  end
92
113
 
93
114
  publisher do
@@ -298,3 +319,239 @@ publisher do
298
319
  end
299
320
  end
300
321
  end
322
+
323
+ publisher do
324
+ name :brakeman
325
+ plugin_id 'brakeman'
326
+ description 'Parses results from Brakeman, a static-analysis vulnerability scanner for Ruby on Rails.'
327
+ jenkins_name 'Brakeman Plugin'
328
+ announced false
329
+
330
+ xml do |params|
331
+
332
+ send('hudson.plugins.brakeman.BrakemanPublisher', 'plugin' => 'brakeman') do
333
+ healthy params[:healthy] || ''
334
+ unHealthy params[:unhealthy] || ''
335
+ thresholdLimit params[:threshold_limit] || 'low'
336
+ pluginName '[BRAKEMAN] '
337
+ defaultEncoding 'UTF-8'
338
+ canRunOnFailed params[:can_run_on_failed] || false
339
+ useStableBuildAsReference params[:use_stable_build_as_reference] || false
340
+ useDeltaValues params[:use_delta_values] || false
341
+
342
+ thresholds = params[:thresholds] || {}
343
+ send('thresholds', 'plugin' => 'analysis-core') do
344
+ unstableTotalAll { text(thresholds[:unstable_total_all] || '') }
345
+ unstableTotalHigh { text(thresholds[:unstable_total_high] || '') }
346
+ unstableTotalNormal { text(thresholds[:unstable_total_normal] || '') }
347
+ unstableTotalLow { text(thresholds[:unstable_total_low] || '') }
348
+ failedTotalAll { text(thresholds[:failed_total_all] || '') }
349
+ failedTotalHigh { text(thresholds[:failed_total_high] || '') }
350
+ failedTotalNormal { text(thresholds[:failed_total_normal] || '') }
351
+ failedTotalLow { text(thresholds[:failed_total_low] || '') }
352
+ end
353
+
354
+ shouldDetectModules { text(params[:should_detect_modules] || false) }
355
+ dontComputeNew { text(params[:dont_compute_new] || true) }
356
+ doNotResolveRelativePaths { text(params[:do_not_resolve_relative_paths] || false) }
357
+ outputFile { text(params[:output_file] || 'brakeman-output.tabs') }
358
+ end
359
+
360
+ end
361
+ end
362
+
363
+ publisher do
364
+ name :claim_broken_build
365
+ plugin_id 'claim'
366
+ description 'This plugin allows users to claim failed builds.'
367
+ jenkins_name 'Jenkins Claim Plugin'
368
+ announced false
369
+
370
+ xml do |allow_claim|
371
+ send('hudson.plugins.claim.ClaimPublisher', 'plugin' => 'claim') if allow_claim
372
+ end
373
+ end
374
+
375
+ publisher do
376
+ name :cobertura_report
377
+ plugin_id 'cobertura'
378
+ description 'This plugin integrates Cobertura coverage reports to Jenkins.'
379
+ jenkins_name 'Cobertura Plugin'
380
+ announced false
381
+
382
+ xml do |params|
383
+ send('hudson.plugins.cobertura.CoberturaPublisher', 'plugin' => 'cobertura') do
384
+
385
+ coberturaReportFile params[:cobertura_report_file]
386
+ onlyStable params[:only_stable] || false
387
+ failUnhealthy params[:fail_unhealthy] || false
388
+ failUnstable params[:fail_unstable] || false
389
+ autoUpdateHealth params[:auto_update_health] || false
390
+ autoUpdateStability params[:auto_update_stability] || false
391
+ zoomCoverageChart params[:zoom_coverage_chart] || false
392
+ maxNumberOfBuilds params[:max_number_of_builds] || 0
393
+ failNoReports params[:fail_no_reports] || true
394
+
395
+ params.send_metric_targets(:failing)
396
+ params.send_metric_targets(:unhealthy)
397
+ params.send_metric_targets(:healthy)
398
+
399
+ sourceEncoding params[:source_encoding] || 'ASCII'
400
+ end
401
+ end
402
+
403
+ end
404
+
405
+ publisher do
406
+ name :email_ext
407
+ plugin_id 'email-ext'
408
+ description 'This plugin is a replacement for Jenkins\'s email publisher.'
409
+ jenkins_name 'Email-ext plugin'
410
+ announced false
411
+
412
+ xml do |params|
413
+ send('hudson.plugins.emailext.ExtendedEmailPublisher', 'plugin' => 'email-ext') do
414
+ recipientList { text(params[:recipient_list] || '$DEFAULT_RECIPIENTS') }
415
+
416
+ unless params[:triggers].nil?
417
+
418
+ configuredTriggers do
419
+ params[:triggers].each do |trigger_params|
420
+
421
+ trigger_type = trigger_params[:type].to_sym
422
+ defaults = params.trigger_defaults[trigger_type]
423
+
424
+ send("hudson.plugins.emailext.plugins.trigger.#{defaults[:name]}") do
425
+ email do
426
+ recipientList { text(trigger_params[:recipient_list] || '') }
427
+ subject { text(trigger_params[:subject] || '$PROJECT_DEFAULT_SUBJECT') }
428
+ body { text(trigger_params[:body] || '$PROJECT_DEFAULT_CONTENT') }
429
+ sendToDevelopers { text(!trigger_params[:send_to_developers].nil? ? trigger_params[:send_to_developers] : defaults[:send_to_developers]) }
430
+ sendToRequester { text(!trigger_params[:send_to_requester].nil? ? trigger_params[:send_to_requester] : defaults[:send_to_requester]) }
431
+ includeCulprits { text(!trigger_params[:include_culprits].nil? ? trigger_params[:include_culprits] : defaults[:include_culprits]) }
432
+ sendToRecipientList { text(!trigger_params[:send_to_recipient_list].nil? ? trigger_params[:send_to_recipient_list] : defaults[:send_to_recipient_list]) }
433
+ attachmentsPattern { text(trigger_params[:attachments_pattern] || '') }
434
+ attachBuildLog { text(trigger_params[:attach_build_log] || false) }
435
+ compressBuildLog { text(trigger_params[:compress_build_log] || false) }
436
+ replyTo { text(trigger_params[:reply_to] || '$PROJECT_DEFAULT_REPLYTO') }
437
+ contentType { text(trigger_params[:content_type] || 'project') }
438
+ end
439
+
440
+ failureCount { text '1' } if trigger_type == :first_failure
441
+ failureCount { text '2' } if trigger_type == :second_failure
442
+ if trigger_type == :prebuild_script || trigger_type == :script
443
+ triggerScript { text(trigger_params[:trigger_script] || '') }
444
+ end
445
+ end
446
+ end
447
+ end
448
+ end
449
+
450
+ contentType { text(params[:content_type] || 'default') }
451
+ defaultSubject { text(params[:default_subject] || '$DEFAULT_SUBJECT') }
452
+ defaultContent { text(params[:default_content] || '$DEFAULT_CONTENT') }
453
+ attachmentsPattern { text(params[:attachments_pattern] || '') }
454
+ presendScript { text(params[:presend_script] || '$DEFAULT_PRESEND_SCRIPT') }
455
+ attachBuildLog { text(params[:attach_build_log] || 'false') }
456
+ compressBuildLog { text(params[:compress_build_log] || 'false') }
457
+ replyTo { text(params[:reply_to] || '$DEFAULT_REPLYTO') }
458
+ saveOutput { text(params[:save_output] || 'false') }
459
+ end
460
+ end
461
+ end
462
+
463
+ publisher do
464
+ name :html_publisher
465
+ plugin_id 'htmlpublisher'
466
+ description 'This plugin publishes HTML reports.'
467
+ jenkins_name 'HTML Publisher Plugin'
468
+ announced false
469
+
470
+ xml do |params|
471
+ send('htmlpublisher.HtmlPublisher', 'plugin' => 'htmlpublisher') do
472
+ send('reportTargets') do
473
+ unless params[:report_targets].nil?
474
+ params[:report_targets].each do |target|
475
+ send('htmlpublisher.HtmlPublisherTarget') do
476
+ reportName target[:report_title] || 'HTML Report'
477
+ reportDir target[:report_dir] || ''
478
+ reportFiles target[:index_pages] || 'index.html'
479
+ keepAll target[:keep_past] || false
480
+ allowMissing target[:allow_missing] || false
481
+ wrapperName 'htmlpublisher-wrapper.html'
482
+ end
483
+ end
484
+ end
485
+ end
486
+ end
487
+ end
488
+ end
489
+
490
+ publisher do
491
+ name :publish_tap_results
492
+ plugin_id 'tap'
493
+ description 'This plug-in adds support to TAP test result files to Jenkins. It lets you specify an ant-like pattern for a directory that contains your TAP files.'
494
+ jenkins_name 'TAP Plugin'
495
+ announced false
496
+
497
+ xml do |params|
498
+ send('org.tap4j.plugin.TapPublisher', 'plugin' => 'tap') do
499
+ testResults params[:test_results]
500
+ failIfNoResults params[:fail_if_no_results] || false
501
+ failedTestsMarkBuildAsFailure params[:failed_test_mark_as_failure] || false
502
+ outputTapToConsole params[:output_to_console] || false
503
+ enableSubtests params[:enable_subtests] || false
504
+ discardOldReports params[:discard_old_reports] || false
505
+ todoIsFailure params[:todo_is_failure] || false
506
+ includeCommentDiagnostics params[:include_comment_diagnostics] || false
507
+ validateNumberOfTests params[:validate_number_tests] || false
508
+ end
509
+ end
510
+
511
+ end
512
+
513
+ publisher do
514
+ name :xunit
515
+ plugin_id 'xunit'
516
+ description 'This plugin makes it possible to record xUnit test reports.'
517
+ jenkins_name 'xUnit Plugin'
518
+ announced false
519
+
520
+ xml do |params|
521
+ send('xunit', 'plugin' => 'xunit') do
522
+ send('types') do
523
+ unless params[:types].nil?
524
+ params[:types].each do |type|
525
+ send(type[:type]) do
526
+ pattern type[:pattern]
527
+ skipNoTestFiles type[:skip_no_test_files] || false
528
+ failIfNotNew type[:fail_if_not_new] || true
529
+ deleteOutputFiles type[:delete_output_files] || true
530
+ stopProcessingIfError type[:stop_processing_error] || true
531
+ end
532
+ end
533
+ end
534
+ end
535
+
536
+ params[:thresholds] ||= {}
537
+ failed_thresholds = params[:thresholds][:failed] || {}
538
+ skipped_thresholds = params[:thresholds][:skipped] || {}
539
+ thresholds do
540
+ send('org.jenkinsci.plugins.xunit.threshold.FailedThreshold') do
541
+ unstableThreshold failed_thresholds[:unstable_threshold] || ''
542
+ unstableNewThreshold failed_thresholds[:unstable_new_threshold] || ''
543
+ failureThreshold failed_thresholds[:failure_threshold] || ''
544
+ failureNewThreshold failed_thresholds[:failure_new_threshold] || ''
545
+ end
546
+ send('org.jenkinsci.plugins.xunit.threshold.SkippedThreshold') do
547
+ unstableThreshold skipped_thresholds[:unstable_threshold] || ''
548
+ unstableNewThreshold skipped_thresholds[:unstable_new_threshold] || ''
549
+ failureThreshold skipped_thresholds[:failure_threshold] || ''
550
+ failureNewThreshold skipped_thresholds[:failure_new_threshold] || ''
551
+ end
552
+ end
553
+
554
+ thresholdMode params[:threshold_mode] || 1
555
+ end
556
+ end
557
+ end