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
@@ -81,4 +81,60 @@ describe 'builders' do
81
81
  expect(node.children.first.content).to eq 'true'
82
82
  end
83
83
  end
84
+
85
+ context 'maven3' do
86
+ before :each do
87
+ allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
88
+ list_installed: { 'maven-plugin' => '20.0' })
89
+ end
90
+
91
+ it 'generates a configuration' do
92
+ params = { builders: { maven3: {} } }
93
+
94
+ JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
95
+
96
+ builder = @n_xml.root.children.first
97
+ expect(builder.name).to match 'org.jfrog.hudson.maven3.Maven3Builder'
98
+ expect(@n_xml.root.css('mavenName').first.text).to eq 'tools-maven-3.0.3'
99
+ end
100
+ end
101
+
102
+ context 'blocking_downstream' do
103
+ before :each do
104
+ allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
105
+ list_installed: { 'parameterized-trigger' => '20.0' })
106
+
107
+ JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
108
+
109
+ builder = @n_xml.root.children.first
110
+ expect(builder.name).to match 'hudson.plugins.parameterizedtrigger.TriggerBuilder'
111
+ end
112
+
113
+ context 'step failure threshold' do
114
+ let(:params) { { builders: { blocking_downstream: { fail: 'FAILURE' } } } }
115
+
116
+ it 'generates a configuration' do
117
+ expect(@n_xml.root.css('buildStepFailureThreshold').first).to_not be_nil
118
+ expect(@n_xml.root.css('buildStepFailureThreshold').first.css('color').first.text).to eq 'RED'
119
+ end
120
+ end
121
+
122
+ context 'unstable threshold' do
123
+ let(:params) { { builders: { blocking_downstream: { mark_unstable: 'UNSTABLE' } } } }
124
+
125
+ it 'generates a configuration' do
126
+ expect(@n_xml.root.css('unstableThreshold').first).to_not be_nil
127
+ expect(@n_xml.root.css('unstableThreshold').first.css('color').first.text).to eq 'YELLOW'
128
+ end
129
+ end
130
+
131
+ context 'failure threshold' do
132
+ let(:params) { { builders: { blocking_downstream: { mark_fail: 'FAILURE' } } } }
133
+
134
+ it 'generates a configuration' do
135
+ expect(@n_xml.root.css('failureThreshold').first).to_not be_nil
136
+ expect(@n_xml.root.css('failureThreshold').first.css('color').first.text).to eq 'RED'
137
+ end
138
+ end
139
+ end
84
140
  end
@@ -15,11 +15,96 @@ describe 'job_attributes' do
15
15
  }
16
16
  end
17
17
 
18
+ before :each do
19
+ properties = Nokogiri::XML::Builder.new { |xml| xml.properties }
20
+ @n_xml = properties.doc
21
+ end
22
+
18
23
  after :each do |example|
19
24
  name = example.description.gsub ' ', '_'
20
25
  File.open("./out/xml/job_attribute_#{name}.xml", 'w') { |f| @n_xml.write_xml_to f }
21
26
  end
22
27
 
28
+ context 'generic' do
29
+ it 'can register a job_attribute' do
30
+ result = job_attribute do
31
+ name :test_generic
32
+ plugin_id :foo
33
+ xml do
34
+ foo :bar
35
+ end
36
+ end
37
+ puts result.inspect
38
+ JenkinsPipelineBuilder.registry.registry[:job].delete :test_generic
39
+ expect(result).to be true
40
+ end
41
+
42
+ it 'fails to register an invalid job_attribute' do
43
+ result = job_attribute do
44
+ name :test_generic
45
+ end
46
+ JenkinsPipelineBuilder.registry.registry[:job].delete :test_generic
47
+ expect(result).to be false
48
+ end
49
+ end
50
+
51
+ context 'parameters' do
52
+ let(:params) { { parameters: [{ type: type, name: :foo, description: :desc, default: :default }] } }
53
+
54
+ before :each do
55
+ JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
56
+ @parameters = @n_xml.root.children.first
57
+ expect(@parameters.name).to match 'hudson.model.ParametersDefinitionProperty'
58
+ end
59
+
60
+ context 'string parameter' do
61
+ let(:type) { 'string' }
62
+ it 'generates correct config' do
63
+ expect(@parameters.to_s).to include 'hudson.model.StringParameterDefinition'
64
+ end
65
+ end
66
+
67
+ context 'password parameter' do
68
+ let(:type) { 'password' }
69
+ it 'generates correct config' do
70
+ expect(@parameters.to_s).to include 'hudson.model.PasswordParameterDefinition'
71
+ end
72
+ end
73
+
74
+ context 'bool parameter' do
75
+ let(:type) { 'bool' }
76
+ it 'generates correct config' do
77
+ expect(@parameters.to_s).to include 'hudson.model.BooleanParameterDefinition'
78
+ end
79
+ end
80
+
81
+ context 'text parameter' do
82
+ let(:type) { 'text' }
83
+ it 'generates correct config' do
84
+ expect(@parameters.to_s).to include 'hudson.model.TextParameterDefinition'
85
+ end
86
+ end
87
+
88
+ context 'choice parameter' do
89
+ let(:params) do
90
+ { parameters: [{ type: 'choice', values: [:foo, :bar], name: :foo, description: :desc, default: :default }] }
91
+ end
92
+
93
+ it 'generates correct config' do
94
+ expect(@parameters.to_s).to include 'hudson.model.ChoiceParameterDefinition'
95
+ expect(@n_xml.root.css('string').map(&:text)).to include 'foo'
96
+ expect(@n_xml.root.css('string').map(&:text)).to include 'bar'
97
+ end
98
+ end
99
+
100
+ context 'defaults to string' do
101
+ let(:type) { 'bad_choice' }
102
+ it 'generates correct config' do
103
+ expect(@parameters.to_s).to include 'hudson.model.StringParameterDefinition'
104
+ end
105
+ end
106
+ end
107
+
23
108
  context 'disabled' do
24
109
  it 'sets disabled' do
25
110
  params = { disabled: true }
@@ -107,43 +107,115 @@ describe 'publishers' do
107
107
  it 'sets the file'
108
108
  end
109
109
 
110
+ context 'cobertura_report' do
111
+ before :each do
112
+ allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
113
+ list_installed: { 'cobertura' => '20.0'
114
+ })
115
+ end
116
+ it 'generates a configuration' do
117
+ params = { publishers: { cobertura_report: {} } }
118
+
119
+ JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
120
+
121
+ publisher = @n_xml.root.children.first
122
+ expect(publisher.name).to match 'hudson.plugins.cobertura.CoberturaPublisher'
123
+ expect(publisher.children.map(&:name)).to_not include 'send_metric_targets'
124
+ expect(publisher.to_xml).to include 'hudson.plugins.cobertura.targets.CoverageMetric'
125
+ end
126
+ end
127
+
128
+ context 'email_ext' do
129
+ before :each do
130
+ allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
131
+ list_installed: { 'email-ext' => '20.0'
132
+ })
133
+ end
134
+ it 'generates a configuration' do
135
+ params = { publishers: { email_ext: { triggers: [{ type: :first_failure }] } } }
136
+
137
+ JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
138
+
139
+ publisher = @n_xml.root.children.first
140
+ expect(publisher.name).to match 'hudson.plugins.emailext.ExtendedEmailPublisher'
141
+ expect(publisher.children.map(&:name)).to_not include 'trigger_defaults'
142
+ expect(publisher.to_xml).to include 'FirstFailureTrigger'
143
+ end
144
+ end
145
+
110
146
  context 'hipchat' do
111
- it 'generates a configuration'
112
- it 'does an option'
147
+ context '0.1.9' do
148
+ before :each do
149
+ allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
150
+ list_installed: { 'hipchat' => '0.1.9' })
151
+ end
152
+ it 'generates a configuration' do
153
+ params = { publishers: { hipchat: {} } }
154
+ hipchat = JenkinsPipelineBuilder.registry.registry[:job][:publishers][:hipchat]
155
+ expect(hipchat.extension.min_version).to eq '0.1.9'
156
+
157
+ JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
158
+
159
+ publisher = @n_xml.root.children.first
160
+ expect(publisher.name).to match 'jenkins.plugins.hipchat.HipChatNotifier'
161
+ children = publisher.children.map(&:name)
162
+ expect(children).to include 'token'
163
+ expect(children).to include 'room'
164
+ expect(children).to include 'startNotification'
165
+ expect(children).to include 'notifySuccess'
166
+ expect(children).to include 'completeJobMessage'
167
+ end
168
+ end
169
+
170
+ context '0' do
171
+ before :each do
172
+ expect(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
173
+ list_installed: { 'hipchat' => '0'
174
+ })
175
+ puts JenkinsPipelineBuilder.registry.versions
176
+ end
177
+
178
+ it 'generates a configuration' do
179
+ expect(JenkinsPipelineBuilder.registry.registry[:job][:publishers][:hipchat].extension.min_version).to eq '0'
180
+ params = { publishers: { hipchat: {} } }
181
+
182
+ JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
183
+
184
+ publisher = @n_xml.root.children.first
185
+ expect(publisher.name).to match 'jenkins.plugins.hipchat.HipChatNotifier'
186
+ children = publisher.children.map(&:name)
187
+ expect(children).to include 'jenkinsUrl'
188
+ expect(children).to include 'room'
189
+ expect(children).to include 'authToken'
190
+ end
191
+ end
113
192
  end
114
193
 
115
194
  context 'git' do
116
195
  it 'generates a configuration'
117
- it 'does an option'
118
196
  end
119
197
 
120
198
  context 'junit_result' do
121
199
  it 'generates a configuration'
122
- it 'does an option'
123
200
  end
124
201
 
125
202
  context 'coverage_result' do
126
203
  it 'generates a configuration'
127
- it 'does an option'
128
204
  end
129
205
 
130
206
  context 'post_build_script' do
131
207
  it 'generates a configuration'
132
- it 'does an option'
133
208
  end
134
209
 
135
210
  context 'groovy_postbuild' do
136
211
  it 'generates a configuration'
137
- it 'does an option'
138
212
  end
139
213
 
140
214
  context 'archive_artifact' do
141
215
  it 'generates a configuration'
142
- it 'does an option'
143
216
  end
144
217
 
145
218
  context 'email_notification' do
146
219
  it 'generates a configuration'
147
- it 'does an option'
148
220
  end
149
221
  end
@@ -0,0 +1,134 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ WRAPPERS = {
3
+ ansicolor: ['0'],
4
+ artifactory: ['0'],
5
+ inject_env_var: ['0'],
6
+ inject_passwords: ['0'],
7
+ maven3artifactory: ['0'],
8
+ nodejs: ['0'],
9
+ rvm: ['0', '0.5'],
10
+ timestamp: ['0'],
11
+ xvfb: ['0']
12
+ }
13
+ PUBLISHERS = {
14
+ archive_artifact: ['0'],
15
+ brakeman: ['0'],
16
+ claim_broken_build: ['0'],
17
+ cobertura_report: ['0'],
18
+ coverage_result: ['0'],
19
+ description_setter: ['0'],
20
+ downstream: ['0'],
21
+ email_ext: ['0'],
22
+ email_notifications: ['0'],
23
+ git: ['0'],
24
+ groovy_postbuild: ['0'],
25
+ hipchat: ['0', '0.1.9'],
26
+ html_publisher: ['0'],
27
+ junit_result: ['0'],
28
+ performance_plugin: ['0'],
29
+ post_build_script: ['0'],
30
+ publish_tap_results: ['0'],
31
+ sonar_result: ['0'],
32
+ xunit: ['0']
33
+ }
34
+ BUILDERS = {
35
+ blocking_downstream: ['0'],
36
+ copy_artifact: ['0'],
37
+ inject_vars_file: ['0'],
38
+ maven3: ['0'],
39
+ multi_job: ['0'],
40
+ remote_job: ['0'],
41
+ shell_command: ['0']
42
+ }
43
+ TRIGGERS = {
44
+ git_push: ['0'],
45
+ periodic_build: ['0'],
46
+ scm_polling: ['0'],
47
+ upstream: ['0']
48
+ }
49
+ JOB_ATTRIBUTES = {
50
+ concurrent_build: ['0'],
51
+ description: ['0'],
52
+ disabled: ['0'],
53
+ discard_old: ['0'],
54
+ hipchat: ['0'],
55
+ inject_env_vars_pre_scm: ['0'],
56
+ parameters: ['0'],
57
+ prepare_environment: ['0'],
58
+ priority: ['0'],
59
+ promoted_builds: ['0'],
60
+ scm_params: ['0', '2.0'],
61
+ throttle: ['0']
62
+ }
63
+
64
+ describe 'built in extensions' do
65
+ before :each do
66
+ @registry = JenkinsPipelineBuilder.registry.registry
67
+ end
68
+
69
+ after :each do
70
+ JenkinsPipelineBuilder.registry.clear_versions
71
+ end
72
+
73
+ context 'builders' do
74
+ it 'has the correct number' do
75
+ expect(@registry[:job][:builders].size).to eq BUILDERS.size
76
+ end
77
+ BUILDERS.each do |builder, versions|
78
+ it "registers #{builder} correctly" do
79
+ expect(@registry[:job][:builders]).to have_key builder
80
+ expect(@registry[:job][:builders][builder]).to have_registered_versions versions
81
+ end
82
+ end
83
+ end
84
+
85
+ context 'triggers' do
86
+ it 'has the correct number' do
87
+ expect(@registry[:job][:triggers].size).to eq TRIGGERS.size
88
+ end
89
+
90
+ TRIGGERS.each do |trigger, versions|
91
+ it "registers #{trigger} correctly" do
92
+ expect(@registry[:job][:triggers]).to have_key trigger
93
+ expect(@registry[:job][:triggers][trigger]).to have_registered_versions versions
94
+ end
95
+ end
96
+ end
97
+
98
+ context 'job_attributes' do
99
+ it 'has the correct number' do
100
+ expect(@registry[:job].size - 4).to eq JOB_ATTRIBUTES.size
101
+ end
102
+
103
+ JOB_ATTRIBUTES.each do |job_attribute, versions|
104
+ it "registers #{job_attribute} correctly" do
105
+ expect(@registry[:job]).to have_key job_attribute
106
+ expect(@registry[:job][job_attribute]).to have_registered_versions versions
107
+ end
108
+ end
109
+ end
110
+
111
+ context 'publishers' do
112
+ it 'has the correct number' do
113
+ expect(@registry[:job][:publishers].size).to eq PUBLISHERS.size
114
+ end
115
+ PUBLISHERS.each do |publisher, versions|
116
+ it "registers #{publisher} correctly" do
117
+ expect(@registry[:job][:publishers]).to have_key publisher
118
+ expect(@registry[:job][:publishers][publisher]).to have_registered_versions versions
119
+ end
120
+ end
121
+ end
122
+
123
+ context 'wrappers' do
124
+ it 'has the correct number' do
125
+ expect(@registry[:job][:wrappers].size).to eq WRAPPERS.size
126
+ end
127
+ WRAPPERS.each do |wrapper, versions|
128
+ it "registers #{wrapper} correctly" do
129
+ expect(@registry[:job][:wrappers]).to have_key wrapper
130
+ expect(@registry[:job][:wrappers][wrapper]).to have_registered_versions versions
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,88 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe 'triggers' do
4
+ after :each do
5
+ JenkinsPipelineBuilder.registry.clear_versions
6
+ end
7
+
8
+ before :all do
9
+ JenkinsPipelineBuilder.credentials = {
10
+ server_ip: '127.0.0.1',
11
+ server_port: 8080,
12
+ username: 'username',
13
+ password: 'password',
14
+ log_location: '/dev/null'
15
+ }
16
+ end
17
+
18
+ before :each do
19
+ trigger = Nokogiri::XML::Builder.new { |xml| xml.triggers }
20
+ @n_xml = trigger.doc
21
+ end
22
+
23
+ after :each do |example|
24
+ name = example.description.gsub ' ', '_'
25
+ require 'fileutils'
26
+ FileUtils.mkdir_p 'out/xml'
27
+ File.open("./out/xml/trigger_#{name}.xml", 'w') { |f| @n_xml.write_xml_to f }
28
+ end
29
+
30
+ context 'generic' do
31
+ it 'can register a trigger' do
32
+ result = trigger do
33
+ name :test_generic
34
+ plugin_id :foo
35
+ xml do
36
+ foo :bar
37
+ end
38
+ end
39
+ JenkinsPipelineBuilder.registry.registry[:job][:triggers].delete :test_generic
40
+ expect(result).to be true
41
+ end
42
+
43
+ it 'fails to register an invalid trigger' do
44
+ result = trigger do
45
+ name :test_generic
46
+ end
47
+ JenkinsPipelineBuilder.registry.registry[:job][:triggers].delete :test_generic
48
+ expect(result).to be false
49
+ end
50
+ end
51
+
52
+ context 'upstream' do
53
+ before :each do
54
+ allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
55
+ list_installed: { 'jenkins-multijob-plugin' => '20.0' })
56
+ end
57
+
58
+ it 'generates an unstable configuration' do
59
+ params = { triggers: { upstream: { status: 'unstable' } } }
60
+
61
+ JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
62
+
63
+ trigger = @n_xml.root.children.first
64
+ expect(trigger.name).to match 'jenkins.triggers.ReverseBuildTrigger'
65
+ expect(trigger.css('name').first.content).to match 'UNSTABLE'
66
+ end
67
+
68
+ it 'generates an failed configuration' do
69
+ params = { triggers: { upstream: { status: 'failed' } } }
70
+
71
+ JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
72
+
73
+ trigger = @n_xml.root.children.first
74
+ expect(trigger.name).to match 'jenkins.triggers.ReverseBuildTrigger'
75
+ expect(trigger.css('name').first.content).to match 'FAILURE'
76
+ end
77
+
78
+ it 'generates an successful configuration' do
79
+ params = { triggers: { upstream: { status: 'successful_this_is_an_else' } } }
80
+
81
+ JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
82
+
83
+ trigger = @n_xml.root.children.first
84
+ expect(trigger.name).to match 'jenkins.triggers.ReverseBuildTrigger'
85
+ expect(trigger.css('name').first.content).to match 'SUCCESS'
86
+ end
87
+ end
88
+ end