jenkins_pipeline_builder 0.13.4 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +2 -1
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +2 -0
  5. data/jenkins_pipeline_builder.gemspec +1 -1
  6. data/lib/jenkins_pipeline_builder/cli/describe.rb +5 -5
  7. data/lib/jenkins_pipeline_builder/cli/helper.rb +2 -5
  8. data/lib/jenkins_pipeline_builder/cli/pipeline.rb +1 -1
  9. data/lib/jenkins_pipeline_builder/compiler.rb +33 -45
  10. data/lib/jenkins_pipeline_builder/extension_set.rb +5 -5
  11. data/lib/jenkins_pipeline_builder/extensions.rb +1 -1
  12. data/lib/jenkins_pipeline_builder/extensions/builders.rb +31 -8
  13. data/lib/jenkins_pipeline_builder/extensions/helpers/extension_helper.rb +5 -5
  14. data/lib/jenkins_pipeline_builder/extensions/job_attributes.rb +6 -6
  15. data/lib/jenkins_pipeline_builder/extensions/publishers.rb +1 -0
  16. data/lib/jenkins_pipeline_builder/generator.rb +16 -21
  17. data/lib/jenkins_pipeline_builder/job.rb +3 -3
  18. data/lib/jenkins_pipeline_builder/job_collection.rb +12 -14
  19. data/lib/jenkins_pipeline_builder/module_registry.rb +2 -2
  20. data/lib/jenkins_pipeline_builder/project.rb +4 -6
  21. data/lib/jenkins_pipeline_builder/pull_request_generator.rb +3 -2
  22. data/lib/jenkins_pipeline_builder/version.rb +1 -1
  23. data/lib/jenkins_pipeline_builder/view.rb +18 -18
  24. data/spec/lib/jenkins_pipeline_builder/compiler_spec.rb +8 -13
  25. data/spec/lib/jenkins_pipeline_builder/extensions/registered_spec.rb +8 -6
  26. data/spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_json_files/project.json +15 -0
  27. data/spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_json_files/view.json +10 -0
  28. data/spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_yaml_files/project.yaml +8 -0
  29. data/spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_yaml_files/view.yaml +5 -0
  30. data/spec/lib/jenkins_pipeline_builder/generator_spec.rb +23 -3
  31. data/spec/lib/jenkins_pipeline_builder/module_registry_spec.rb +6 -6
  32. data/spec/lib/jenkins_pipeline_builder/pull_request_generator_spec.rb +10 -13
  33. metadata +12 -4
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmI1MTFmZmVkYmNkODgyMGYzNmZjYjFhMmUxZmFlZjkwYzU1MGNkYQ==
4
+ MDBiZGQ1ODhjMWU2ZTE0Mjk0MDM5ZjIzMmUyYzMwOTcyMDc2ODJkMA==
5
5
  data.tar.gz: !binary |-
6
- ODFhNzAzMjA0ODI5Mjg1MTI0YjMwZDgyMDk2YmM5MmJmYjlhOWYyOQ==
6
+ OTExNDQ5YjYyYTlhYzUxNjgxY2QzMDI4ODkyZDM5NjQ4MDI1NDg1Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTE1NjRhYWUyZGRjMDBiNTE0NWFlY2U1NDI0Y2YwMjI5NTU3NDAwMTI5MDlj
10
- M2Q1NWM4Njc0YzljNDUwNjgyODQ1ZGZhMjY4ZjcwNTQxOWFhZGQxM2EyZWEx
11
- ZDFkMjk0NTkyZTlmY2FhMzU5Y2M0ODEwYzMyNjczMTMzOTA2Mjk=
9
+ ZmRkMmE4OTA3MDA3YjZkM2Q2NDJkZGFhMTA1Njc0MGQ1N2E2NTBhYzgzYWM1
10
+ Mjc5ZjMzNjVhMDJjODI3ZjQ4ZDc4MTdjN2VlNjI0NjlmN2M1NDEyNWY2OWI4
11
+ YmMzMDJjNTZmYmIzNTk4NzNkMjc5MWRlMGE2ZDFlNTkxOWVjMGQ=
12
12
  data.tar.gz: !binary |-
13
- NWI0YjJhMjU2ZjUzZWNhZDdjZTk5OTU3NjE2NmQxYmRmNTZjNjdhMzJjZDYy
14
- NTZkMDc1YjRjNjhkMTNkNmQ3YjJkNjFkNGU4MDkxNjMxNTUwNGEwYzVlYmY4
15
- NWEwNmEwMTZhNGExZjJjZWIxM2FhMDk3ZGU5MGYwYmI4OTUxYTc=
13
+ ZjEwYjc1ODg1MzliMzNkYzkwM2M2ZDU4MGJhNjc4M2EwMTlmMWEzYTNlMmRi
14
+ Zjk3ZTM3YTlkYzBmOThjOWI1ODJhNzgyMzFhNGI2OWM3YTk5NWY3NWY5OThh
15
+ Y2M4ZWRmOWQ3YTA2MWJjMjk3OWZhZDkwZGI0YmJlZTgxYTQyOWY=
data/.gitignore CHANGED
@@ -3,4 +3,5 @@ out
3
3
  Gemfile.lock
4
4
  *.gem
5
5
  .DS_Store
6
- .idea
6
+ .idea
7
+ .byebug_history
@@ -1 +1 @@
1
- ruby-2.0.0-p247
1
+ ruby-2.2.4
@@ -2,6 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1.4
4
4
  - 2.0.0
5
+ before_install:
6
+ - gem install bundler
5
7
  deploy:
6
8
  provider: rubygems
7
9
  api_key:
@@ -33,7 +33,7 @@ automating Job & Pipeline creation from the YAML files checked-in with your appl
33
33
  spec.add_development_dependency 'bump'
34
34
  spec.add_development_dependency 'json'
35
35
  spec.add_development_dependency 'gem-release'
36
- spec.add_development_dependency 'pry'
36
+ spec.add_development_dependency 'byebug'
37
37
  spec.add_development_dependency 'simplecov'
38
38
  spec.add_development_dependency 'simplecov-rcov'
39
39
  spec.add_development_dependency 'kwalify'
@@ -28,11 +28,11 @@ module JenkinsPipelineBuilder
28
28
  klass_name = entry.to_s.classify
29
29
  # rubocop:disable Style/AccessModifierIndentation
30
30
  klass = Class.new(Thor) do
31
- if entry == :job_attributes
32
- extensions = JenkinsPipelineBuilder.registry.registry[:job].select { |_, x| x.is_a? ExtensionSet }
33
- else
34
- extensions = JenkinsPipelineBuilder.registry.registry[:job][entry]
35
- end
31
+ extensions = if entry == :job_attributes
32
+ JenkinsPipelineBuilder.registry.registry[:job].select { |_, x| x.is_a? ExtensionSet }
33
+ else
34
+ JenkinsPipelineBuilder.registry.registry[:job][entry]
35
+ end
36
36
 
37
37
  extensions.each do |key, extset|
38
38
  # TODO: don't just take the first
@@ -71,11 +71,8 @@ module JenkinsPipelineBuilder
71
71
  end
72
72
 
73
73
  def self.process_creds_file(file)
74
- if file.end_with? 'json'
75
- return JSON.parse(IO.read(File.expand_path(file)))
76
- else
77
- return YAML.load_file(File.expand_path(file))
78
- end
74
+ return JSON.parse(IO.read(File.expand_path(file))) if file.end_with? 'json'
75
+ YAML.load_file(File.expand_path(file))
79
76
  end
80
77
 
81
78
  def self.process_cli_creds(options)
@@ -34,7 +34,7 @@ module JenkinsPipelineBuilder
34
34
  desc 'bootstrap Path', 'Generates pipeline from folder or a file'
35
35
  def bootstrap(path, project_name = nil)
36
36
  failed = Helper.setup(parent_options).bootstrap(path, project_name)
37
- fail 'Encountered error during run' unless failed.empty?
37
+ raise 'Encountered error during run' unless failed.empty?
38
38
  end
39
39
 
40
40
  desc 'pull_request Path', 'Generates jenkins jobs based on a git pull request.'
@@ -44,9 +44,15 @@ module JenkinsPipelineBuilder
44
44
  my_settings_bag.merge(bag)
45
45
  end
46
46
 
47
+ def compile_job(item, settings = {})
48
+ new_item = compile(item, settings)
49
+ [true, new_item]
50
+ rescue => e
51
+ return [false, [e.message]]
52
+ end
53
+
47
54
  def compile(item, settings = {})
48
- success, item = handle_enable(item, settings)
49
- return false, item unless success
55
+ item = handle_enable(item, settings)
50
56
 
51
57
  case item
52
58
  when String
@@ -56,16 +62,16 @@ module JenkinsPipelineBuilder
56
62
  when Array
57
63
  return compile_array item, settings
58
64
  end
59
- [true, item]
65
+ item
60
66
  end
61
67
 
62
68
  def handle_enable(item, settings)
63
- return true, item unless item.is_a? Hash
69
+ return item unless item.is_a? Hash
64
70
  if enable_block_present? item
65
71
  enabled_switch = resolve_value(item[:enabled], settings)
66
- return [true, {}] if enabled_switch == 'false'
72
+ return {} if enabled_switch == 'false'
67
73
  if enabled_switch != 'true'
68
- return [false, { 'value error' => "Invalid value for #{item[:enabled]}: #{enabled_switch}" }]
74
+ raise "Invalid value for #{item[:enabled]}: #{enabled_switch}"
69
75
  end
70
76
  if item[:parameters].is_a? Hash
71
77
  item = item.merge item[:parameters]
@@ -75,7 +81,7 @@ module JenkinsPipelineBuilder
75
81
  item = item[:parameters]
76
82
  end
77
83
  end
78
- [true, item]
84
+ item
79
85
  end
80
86
 
81
87
  private
@@ -85,64 +91,44 @@ module JenkinsPipelineBuilder
85
91
  end
86
92
 
87
93
  def compile_string(item, settings)
88
- errors = {}
89
- new_value = resolve_value(item, settings)
90
- errors[item] = "Failed to resolve #{item}" if new_value.nil?
91
- return false, errors unless errors.empty?
92
- [true, new_value]
94
+ resolve_value(item, settings)
95
+ rescue => e
96
+ raise "Failed to resolve #{item} because: #{e.message}"
93
97
  end
94
98
 
95
99
  def compile_array(array, settings)
96
- errors = {}
97
100
  result = []
98
101
  array.each do |value|
99
- success, payload = compile_array_item value, settings, array
100
- errors[value] = payload unless success
102
+ payload = compile_array_item value, settings, array
101
103
  result << payload
102
104
  end
103
- return false, errors unless errors.empty?
104
- [true, result]
105
+ result
105
106
  end
106
107
 
107
108
  def compile_array_item(item, settings, array)
108
- success, payload = compile(item, settings)
109
- return false, "found a nil value when processing following array:\n #{array.inspect}" if item.nil?
110
- return false, payload unless success
111
- return false, "Failed to resolve:\n===>item #{item}\n\n===>of list: #{array.inspect}" if payload.nil?
112
- [true, payload]
109
+ raise "Found a nil value when processing following array:\n #{array.inspect}" if item.nil?
110
+ payload = compile(item, settings)
111
+ raise "Failed to resolve:\n===>item #{item}\n\n===>of list: #{array.inspect}" if payload.nil?
112
+ payload
113
113
  end
114
114
 
115
- def compile_item(key, value, errors, settings)
115
+ def compile_item(key, value, settings)
116
116
  if value.nil?
117
- errors[key] = "key: #{key} has a nil value, this is often a yaml syntax error. Skipping children and siblings"
118
- return false, errors[key]
119
- end
120
- success, payload = compile(value, settings)
121
- unless success
122
- errors.merge!(payload)
123
- return false, payload
117
+ raise "key: #{key} has a nil value, this is often a yaml syntax error. Skipping children and siblings"
124
118
  end
125
- if payload.nil?
126
- errors[key] = "Failed to resolve:\n===>key: #{key}\n\n===>value: #{value}\n\n===>of: #{item}"
127
- return false, errors[key]
128
- end
129
- [true, payload]
119
+ payload = compile(value, settings)
120
+ raise "Failed to resolve:\n===>key: #{key}\n\n===>value: #{value} payload" if payload.nil?
121
+ payload
130
122
  end
131
123
 
132
124
  def compile_hash(item, settings)
133
- success, item = handle_enable(item, settings)
134
- return false, item unless success
135
-
136
- errors = {}
125
+ item = handle_enable(item, settings)
137
126
  result = {}
138
-
139
127
  item.each do |key, value|
140
- success, payload = compile_item(key, value, errors, settings)
141
- next unless success
128
+ payload = compile_item(key, value, settings)
142
129
  result[key] = payload unless payload == {}
143
130
  end
144
- return false, errors unless errors.empty?
145
- [true, result]
131
+ result
146
132
  end
147
133
 
148
134
  def resolve_value(value, settings)
@@ -155,6 +141,7 @@ module JenkinsPipelineBuilder
155
141
  end
156
142
 
157
143
  settings = settings.with_indifferent_access
144
+ # TODO: this is actually a shallow copy and should be fixed
158
145
  value_s = value.to_s.clone
159
146
  correct_job_names! value_s
160
147
  # Then we look for normal values to replace
@@ -165,7 +152,8 @@ module JenkinsPipelineBuilder
165
152
  vars = value_s.scan(/{{([^{}@]+)}}/).flatten
166
153
  vars.select! do |var|
167
154
  var_val = settings[var]
168
- value_s.gsub!("{{#{var}}}", var_val.to_s) unless var_val.nil?
155
+ raise "Could not find defined substitution variable: #{var}" if var_val.nil?
156
+ value_s.gsub!("{{#{var}}}", var_val.to_s)
169
157
  var_val.nil?
170
158
  end
171
159
  return nil if vars.count != 0
@@ -7,7 +7,7 @@ module JenkinsPipelineBuilder
7
7
  :description,
8
8
  :announced,
9
9
  :type
10
- ]
10
+ ].freeze
11
11
  SET_METHODS.each do |method_name|
12
12
  define_method method_name do |value = nil|
13
13
  return settings[method_name] if value.nil?
@@ -54,7 +54,7 @@ module JenkinsPipelineBuilder
54
54
  return @version if @version
55
55
  reg = JenkinsPipelineBuilder.registry
56
56
  version = reg.versions[settings[:plugin_id]]
57
- fail "Plugin #{settings[:name]} is not installed (plugin_id: #{settings[:plugin_id]})" if version.nil?
57
+ raise "Plugin #{settings[:name]} is not installed (plugin_id: #{settings[:plugin_id]})" if version.nil?
58
58
  self.installed_version = version
59
59
  @version
60
60
  end
@@ -66,7 +66,7 @@ module JenkinsPipelineBuilder
66
66
  extension = versions[highest_allowed_version]
67
67
 
68
68
  unless extension
69
- fail "Can't find version of #{name} lte #{installed_version}, available versions: #{versions.keys.map(&:to_s)}"
69
+ raise "Can't find version of #{name} lte #{installed_version}, available versions: #{versions.keys.map(&:to_s)}"
70
70
  end
71
71
  extension
72
72
  end
@@ -81,7 +81,7 @@ module JenkinsPipelineBuilder
81
81
  mismatch.each do |error|
82
82
  puts error
83
83
  end
84
- fail 'Values did not match, cannot merge extension sets' if mismatch.any?
84
+ raise 'Values did not match, cannot merge extension sets' if mismatch.any?
85
85
 
86
86
  self.extensions = versions.merge(other_set.versions).values
87
87
  end
@@ -100,7 +100,7 @@ module JenkinsPipelineBuilder
100
100
  deprecation_warning(settings[:name], 'xml')
101
101
  end
102
102
  unless block
103
- fail "no block found for version #{version}" unless blocks.key version
103
+ raise "no block found for version #{version}" unless blocks.key version
104
104
  return blocks[version][:block]
105
105
  end
106
106
  store_xml version, block, path
@@ -35,7 +35,7 @@ module JenkinsPipelineBuilder
35
35
  after: false,
36
36
  xml: false,
37
37
  parameters: []
38
- }
38
+ }.freeze
39
39
  EXT_METHODS.keys.each do |method_name|
40
40
  define_method method_name do |value = nil|
41
41
  return instance_variable_get("@#{method_name}") if value.nil?
@@ -282,14 +282,10 @@ builder do
282
282
  else
283
283
  send('selector', 'class' => 'hudson.plugins.copyartifact.StatusBuildSelector')
284
284
  end
285
- if params[:fingerprint].nil?
285
+ if params[:fingerprint].nil? || params[:fingerprint].to_s == 'true'
286
286
  doNotFingerprintArtifacts false
287
287
  else
288
- if params[:fingerprint].to_s == 'true'
289
- doNotFingerprintArtifacts false
290
- else
291
- doNotFingerprintArtifacts true
292
- end
288
+ doNotFingerprintArtifacts true
293
289
  end
294
290
  flatten true if params[:flatten]
295
291
  optional true if params[:optional]
@@ -307,10 +303,10 @@ builder do
307
303
  xml do |params|
308
304
  send('hudson.plugins.groovy.SystemGroovy', 'plugin' => 'groovy@1.24') do
309
305
  if params.key?(:script) && params.key?(:file)
310
- fail 'Configuration invalid. Both \'script\' and \'file\' keys can not be specified'
306
+ raise 'Configuration invalid. Both \'script\' and \'file\' keys can not be specified'
311
307
  end
312
308
  unless params.key?(:script) || params.key?(:file)
313
- fail 'Configuration invalid. At least one of \'script\' and \'file\' keys must be specified'
309
+ raise 'Configuration invalid. At least one of \'script\' and \'file\' keys must be specified'
314
310
  end
315
311
 
316
312
  scriptSource('class' => 'hudson.plugins.groovy.StringScriptSource') do
@@ -381,4 +377,31 @@ builder do
381
377
  filterPattern params[:filterPattern]
382
378
  end
383
379
  end
380
+
381
+ builder do
382
+ name :sonar_standalone
383
+ plugin_id 'sonar'
384
+ description 'Quickly benefit from Sonar, the open source platform for Continuous Inspection of code quality.'
385
+ jenkins_name 'SonarQube Plugin'
386
+ announced false
387
+ parameters [
388
+ :sonarInstallation,
389
+ :taskToRun,
390
+ :jdk,
391
+ :pathToProjectProperties,
392
+ :projectProperties,
393
+ :jvmOptions
394
+ ]
395
+
396
+ xml do |params|
397
+ send('hudson.plugins.sonar.SonarRunnerBuilder', 'plugin' => 'sonar@2.1') do
398
+ installationName params[:sonarInstallation]
399
+ project params[:pathToProjectProperties]
400
+ properties params[:projectProperties]
401
+ javaOpts params[:jvmOptions]
402
+ jdk params[:jdk]
403
+ task params[:taskToRun]
404
+ end
405
+ end
406
+ end
384
407
  end
@@ -6,11 +6,11 @@ class ExtensionHelper < SimpleDelegator
6
6
  # That will allow for defaults to be pulled out of the extension and it
7
7
  # will also let better enable overriding of those values that do not have
8
8
  # an option to do so currently.
9
- if params.is_a? Hash
10
- @params = defaults.merge params
11
- else
12
- @params = params
13
- end
9
+ @params = if params.is_a? Hash
10
+ defaults.merge params
11
+ else
12
+ params
13
+ end
14
14
  @builder = builder
15
15
  super @params
16
16
  end
@@ -32,7 +32,7 @@ job_attribute do
32
32
  end
33
33
 
34
34
  xml path: '//project' do |description|
35
- description "#{description}"
35
+ description description.to_s
36
36
  end
37
37
  end
38
38
 
@@ -44,7 +44,7 @@ job_attribute do
44
44
  announced false
45
45
 
46
46
  xml path: '//project' do |jdk|
47
- jdk "#{jdk}"
47
+ jdk jdk.to_s
48
48
  end
49
49
  end
50
50
 
@@ -60,7 +60,7 @@ job_attribute do
60
60
  end
61
61
 
62
62
  xml path: '//project' do |disabled|
63
- disabled "#{disabled}"
63
+ disabled disabled.to_s
64
64
  end
65
65
  end
66
66
 
@@ -169,7 +169,7 @@ job_attribute do
169
169
  extensions do
170
170
  if params[:changelog_to_branch]
171
171
  opts = params[:changelog_to_branch]
172
- fail 'remote and branch are required for changelog_to_branch' unless opts[:remote] && opts[:branch]
172
+ raise 'remote and branch are required for changelog_to_branch' unless opts[:remote] && opts[:branch]
173
173
  send('hudson.plugins.git.extensions.impl.ChangelogToBranch') do
174
174
  options do
175
175
  compareRemote opts[:remote]
@@ -215,7 +215,7 @@ job_attribute do
215
215
  announced false
216
216
 
217
217
  xml path: '//properties' do |params|
218
- fail 'No HipChat room specified' unless params[:room]
218
+ raise 'No HipChat room specified' unless params[:room]
219
219
 
220
220
  send('jenkins.plugins.hipchat.HipChatNotifier_-HipChatJobProperty') do
221
221
  room params[:room]
@@ -257,7 +257,7 @@ job_attribute do
257
257
  send('hudson.model.ParametersDefinitionProperty') do
258
258
  parameterDefinitions do
259
259
  params.each do |param|
260
- send(params.param_type param) do
260
+ send(params.param_type(param)) do
261
261
  name param[:name]
262
262
  description param[:description]
263
263
  defaultValue param[:default]
@@ -315,6 +315,7 @@ publisher do
315
315
  settings class: 'jenkins.mvn.DefaultSettingsProvider'
316
316
  globalSettings class: 'jenkins.mvn.DefaultGlobalSettingsProvider'
317
317
  usePrivateRepository false
318
+ installationName params[:installation_name]
318
319
  end
319
320
  end
320
321
  end
@@ -86,11 +86,11 @@ module JenkinsPipelineBuilder
86
86
 
87
87
  def resolve_job_by_name(name, settings = {})
88
88
  job = job_collection.get_item(name)
89
- fail "Failed to locate job by name '#{name}'" if job.nil?
89
+ raise "Failed to locate job by name '#{name}'" if job.nil?
90
90
  job_value = job[:value]
91
91
  logger.debug "Compiling job #{name}"
92
92
  compiler = JenkinsPipelineBuilder::Compiler.new self
93
- success, payload = compiler.compile(job_value, settings)
93
+ success, payload = compiler.compile_job(job_value, settings)
94
94
  [success, payload]
95
95
  end
96
96
 
@@ -115,11 +115,11 @@ module JenkinsPipelineBuilder
115
115
  end
116
116
 
117
117
  def publish(project_name)
118
- if job_collection.projects.any?
119
- errors = publish_project(project_name)
120
- else
121
- errors = publish_jobs(job_collection.standalone_jobs)
122
- end
118
+ errors = if job_collection.projects.any?
119
+ publish_project(project_name)
120
+ else
121
+ publish_jobs(job_collection.standalone_jobs)
122
+ end
123
123
  print_compile_errors errors
124
124
  errors
125
125
  end
@@ -142,12 +142,9 @@ module JenkinsPipelineBuilder
142
142
  end
143
143
 
144
144
  def print_project_errors(errors)
145
- errors.each do |k, v|
146
- puts "Encountered errors processing: #{k}:"
147
- v.each do |key, error|
148
- puts " key: #{key} had the following error:"
149
- puts " #{error.inspect}"
150
- end
145
+ errors.each do |error|
146
+ puts 'Encountered errors processing:'
147
+ puts error.inspect
151
148
  end
152
149
  end
153
150
 
@@ -210,12 +207,10 @@ module JenkinsPipelineBuilder
210
207
 
211
208
  def create_jobs_and_views(project)
212
209
  success, payload = resolve_project(project)
213
- if success
214
- logger.info 'successfully resolved project'
215
- compiled_project = payload
216
- else
217
- return { project_name: 'Failed to resolve' }
218
- end
210
+ return { project_name: 'Failed to resolve' } unless success
211
+
212
+ logger.info 'successfully resolved project'
213
+ compiled_project = payload
219
214
 
220
215
  errors = publish_jobs(compiled_project[:value][:jobs]) if compiled_project[:value][:jobs]
221
216
  return errors unless compiled_project[:value][:views]
@@ -225,14 +220,14 @@ module JenkinsPipelineBuilder
225
220
 
226
221
  def publish_project(project_name)
227
222
  project = job_collection.projects.find { |p| p[:name] == project_name }
228
- create_jobs_and_views(project || fail("Project #{project_name} not found!"))
223
+ create_jobs_and_views(project || raise("Project #{project_name} not found!"))
229
224
  end
230
225
 
231
226
  def publish_jobs(jobs, errors = {})
232
227
  jobs.each do |i|
233
228
  logger.info "Processing #{i}"
234
229
  job = i[:result]
235
- fail "Result is empty for #{i}" if job.nil?
230
+ raise "Result is empty for #{i}" if job.nil?
236
231
  job = Job.new job
237
232
  success, payload = job.create_or_update
238
233
  errors[job.name] = payload unless success
@@ -29,7 +29,7 @@ module JenkinsPipelineBuilder
29
29
  end
30
30
 
31
31
  def to_xml
32
- fail 'Job name is not specified' unless name
32
+ raise 'Job name is not specified' unless name
33
33
 
34
34
  logger.info "Creating Yaml Job #{job}"
35
35
  job[:job_type] = 'free_style' unless job[:job_type]
@@ -59,7 +59,7 @@ module JenkinsPipelineBuilder
59
59
 
60
60
  def local_output(xml)
61
61
  logger.info "Will create job #{job}"
62
- logger.info "#{xml}" if @debug
62
+ logger.info xml.to_s if @debug
63
63
  FileUtils.mkdir_p(out_dir) unless File.exist?(out_dir)
64
64
  File.open("#{out_dir}/#{name}.xml", 'w') { |f| f.write xml }
65
65
  [true, nil]
@@ -112,7 +112,7 @@ module JenkinsPipelineBuilder
112
112
  # I'm pretty unclear what these templates are...
113
113
  if params.key?(:template)
114
114
  template_name = params[:template]
115
- fail "Job template '#{template_name}' can't be resolved." unless @job_templates.key?(template_name)
115
+ raise "Job template '#{template_name}' can't be resolved." unless @job_templates.key?(template_name)
116
116
  params.delete(:template)
117
117
  template = @job_templates[template_name]
118
118
  puts "Template found: #{template}"
@@ -2,7 +2,7 @@ module JenkinsPipelineBuilder
2
2
  class JobCollection
3
3
  attr_accessor :collection, :remote_dependencies
4
4
  attr_reader :loaded
5
- alias_method :loaded?, :loaded
5
+ alias loaded? loaded
6
6
 
7
7
  def initialize
8
8
  @collection = {}
@@ -70,15 +70,17 @@ module JenkinsPipelineBuilder
70
70
  private
71
71
 
72
72
  def load_file(path, remote = false)
73
- if path.end_with? 'json'
74
- hash = JSON.parse(IO.read(path))
75
- else # elsif path.end_with?("yml") || path.end_with?("yaml")
76
- hash = YAML.load_file(path)
77
- end
73
+ hash = if path.end_with? 'json'
74
+ JSON.parse(IO.read(path))
75
+ else # elsif path.end_with?("yml") || path.end_with?("yaml")
76
+ YAML.load_file(path)
77
+ end
78
78
  logger.info "Loading file #{path}"
79
79
  hash.each do |section|
80
80
  load_section section, remote
81
81
  end
82
+ rescue StandardError => err
83
+ raise "There was an error while parsing a file #{err.message}"
82
84
  end
83
85
 
84
86
  def load_section(section, remote)
@@ -100,14 +102,10 @@ module JenkinsPipelineBuilder
100
102
  if collection.key?(name)
101
103
  existing_remote = collection[name.to_s][:remote]
102
104
  # skip if the existing item is local and the new item is remote
103
- if remote && !existing_remote
104
- return
105
- # override if the existing item is remote and the new is local
106
- elsif existing_remote && !remote
107
- logger.info "Duplicate item with name '#{name}' was detected from the remote folder."
108
- else
109
- fail "Duplicate item with name '#{name}' was detected."
110
- end
105
+ return if remote && !existing_remote
106
+ raise "Duplicate item with name '#{name}' was detected." unless existing_remote && !remote
107
+ # override if the existing item is remote and the new is local
108
+ logger.info "Duplicate item with name '#{name}' was detected from the remote folder."
111
109
  end
112
110
  collection[name.to_s] = { name: name.to_s, type: key, value: value, remote: remote }
113
111
  end
@@ -90,7 +90,7 @@ module JenkinsPipelineBuilder
90
90
  params.each do |key, value|
91
91
  next unless registry.is_a? Hash
92
92
  unless registry.key? key
93
- fail "!!!! could not find key #{key} !!!!" if strict
93
+ raise "!!!! could not find key #{key} !!!!" if strict
94
94
  next
95
95
  end
96
96
  reg_value = registry[key]
@@ -115,7 +115,7 @@ module JenkinsPipelineBuilder
115
115
  def execute_extension(ext, value, n_xml)
116
116
  logger.debug "Using #{ext.type} #{ext.name} version #{ext.min_version}"
117
117
  success = ext.execute value, n_xml
118
- fail 'Encountered errors compiling the xml' unless success
118
+ raise 'Encountered errors compiling the xml' unless success
119
119
  end
120
120
  end
121
121
  end
@@ -10,12 +10,10 @@ module JenkinsPipelineBuilder
10
10
 
11
11
  def publish
12
12
  success, payload = resolve_project(input)
13
- if success
14
- logger.info 'successfully resolved project'
15
- compiled_project = payload
16
- else
17
- return { project_name: 'Failed to resolve' }
18
- end
13
+ return { project_name: 'Failed to resolve' } unless success
14
+
15
+ logger.info 'successfully resolved project'
16
+ compiled_project = payload
19
17
 
20
18
  self.errors = publish_jobs(compiled_project[:value][:jobs]) if compiled_project[:value][:jobs]
21
19
  return unless compiled_project[:value][:views]
@@ -25,12 +25,13 @@ module JenkinsPipelineBuilder
25
25
  attr_accessor :open_prs, :application_name
26
26
 
27
27
  def initialize(defaults = {})
28
- @application_name = defaults[:application_name] || fail('Please set "application_name" in your project!')
28
+ @application_name = defaults[:application_name] || raise('Please set "application_name" in your project!')
29
29
  @open_prs = active_prs defaults[:github_site], defaults[:git_org], defaults[:git_repo_name]
30
30
  end
31
31
 
32
32
  def convert!(job_collection, pr)
33
33
  job_collection.defaults[:value][:application_name] = "#{application_name}-PR#{pr}"
34
+ job_collection.defaults[:value][:pull_request_number] = pr.to_s
34
35
  job_collection.jobs.each { |j| override j[:value], pr }
35
36
  end
36
37
 
@@ -56,7 +57,7 @@ module JenkinsPipelineBuilder
56
57
  end
57
58
 
58
59
  def active_prs(git_url, git_org, git_repo)
59
- (git_url && git_org && git_repo) || fail('Please set github_site, git_org and git_repo_name in your project.')
60
+ (git_url && git_org && git_repo) || raise('Please set github_site, git_org and git_repo_name in your project.')
60
61
  # Build the Git URL
61
62
  url = "#{git_url}/api/v3/repos/#{git_org}/#{git_repo}/pulls"
62
63
  # Download the JSON Data from the API
@@ -21,5 +21,5 @@
21
21
  #
22
22
 
23
23
  module JenkinsPipelineBuilder
24
- VERSION = '0.13.4'
24
+ VERSION = '0.14.0'.freeze
25
25
  end
@@ -35,11 +35,11 @@ module JenkinsPipelineBuilder
35
35
  end
36
36
 
37
37
  def generate(path)
38
- if path.end_with? 'json'
39
- hash = JSON.parse(IO.read(path))
40
- else
41
- hash = YAML.load_file(path)
42
- end
38
+ hash = if path.end_with? 'json'
39
+ JSON.parse(IO.read(path))
40
+ else
41
+ YAML.load_file(path)
42
+ end
43
43
 
44
44
  hash.each do |item|
45
45
  Utils.symbolize_keys_deep!(item)
@@ -66,7 +66,7 @@ module JenkinsPipelineBuilder
66
66
  #
67
67
  def create(params)
68
68
  # Name is a required parameter. Raise an error if not specified
69
- fail ArgumentError, 'Name is required for creating view' unless params.is_a?(Hash) && params[:name]
69
+ raise ArgumentError, 'Name is required for creating view' unless params.is_a?(Hash) && params[:name]
70
70
  clean_up_views(params) unless JenkinsPipelineBuilder.debug
71
71
  params[:type] ||= 'listview'
72
72
  create_base_view(params[:name], params[:type], params[:parent_view])
@@ -90,16 +90,19 @@ module JenkinsPipelineBuilder
90
90
  if params[:parent_view]
91
91
  create_base_view(params[:parent_view], 'nestedView') unless exists?(params[:parent_view])
92
92
  delete(params[:name], params[:parent_view]) if exists?(params[:name], params[:parent_view])
93
- else
94
- delete(params[:name]) if exists?(params[:name])
93
+ elsif exists?(params[:name])
94
+ delete(params[:name])
95
95
  end
96
96
  end
97
97
 
98
98
  def post_params(params)
99
99
  payload = post_payload params
100
- payload.merge!('filterQueue' => 'on') if params[:filter_queue]
101
- payload.merge!('filterExecutors' => 'on') if params[:filter_executors]
102
- payload.merge!('useincluderegex' => 'on', 'includeRegex' => params[:regex]) if params[:regex]
100
+ payload['filterQueue'] = 'on' if params[:filter_queue]
101
+ payload['filterExecutors'] = 'on' if params[:filter_executors]
102
+ if params[:regex]
103
+ payload['useincluderegex'] = 'on'
104
+ payload['includeRegex'] = params[:regex]
105
+ end
103
106
  payload
104
107
  end
105
108
 
@@ -113,7 +116,7 @@ module JenkinsPipelineBuilder
113
116
  'statusFilter' => '',
114
117
  'columns' => get_columns(params[:type])
115
118
  }
116
- json.merge!('groupingRules' => params[:groupingRules]) if params[:groupingRules]
119
+ json['groupingRules'] = params[:groupingRules] if params[:groupingRules]
117
120
 
118
121
  {
119
122
  'name' => params[:name],
@@ -133,7 +136,7 @@ module JenkinsPipelineBuilder
133
136
  'dashboardView' => 'hudson.plugins.view.dashboard.Dashboard',
134
137
  'multijobView' => 'com.tikal.jenkins.plugins.multijob.views.MultiJobView'
135
138
  }
136
- fail "Type #{type} is not supported by Jenkins." unless types.keys.include? type
139
+ raise "Type #{type} is not supported by Jenkins." unless types.keys.include? type
137
140
  types[type]
138
141
  end
139
142
 
@@ -211,11 +214,8 @@ module JenkinsPipelineBuilder
211
214
  path = parent_view.nil? ? '' : "/view/#{parent_view}"
212
215
  response_json = @client.api_get_request(path)
213
216
  response_json['views'].each do |view|
214
- if ignorecase
215
- view_names << view['name'] if view['name'] =~ /#{filter}/i
216
- else
217
- view_names << view['name'] if view['name'] =~ /#{filter}/
218
- end
217
+ filter_exp = ignorecase ? /#{filter}/i : /#{filter}/
218
+ view_names << view['name'] if view['name'] =~ filter_exp
219
219
  end
220
220
  view_names
221
221
  end
@@ -63,7 +63,7 @@ describe JenkinsPipelineBuilder::Compiler do
63
63
  builders: [{ shell_command: "echo 'Running DummyPipeline'" }]
64
64
  }
65
65
  result = compiler.compile(job, settings_bag)
66
- expect(result[1]).to eq(job_compiled)
66
+ expect(result).to eq(job_compiled)
67
67
  end
68
68
 
69
69
  it 'compiles a job with a downstream name change' do
@@ -96,7 +96,7 @@ describe JenkinsPipelineBuilder::Compiler do
96
96
  publishers: [{ downstream: { project: 'DummyPipeline-02' } }]
97
97
  }
98
98
  result = compiler.compile(job, settings_bag)
99
- expect(result[1]).to eq(job_compiled)
99
+ expect(result).to eq(job_compiled)
100
100
  end
101
101
 
102
102
  it 'compiles an enabled job with a string parameter' do
@@ -107,7 +107,7 @@ describe JenkinsPipelineBuilder::Compiler do
107
107
  settings_bag = { var: 'this_is_a_var', name: 'name' }
108
108
 
109
109
  result = compiler.compile(my_job, settings_bag)
110
- expect(result[1]).to eq(compiled_job)
110
+ expect(result).to eq(compiled_job)
111
111
  end
112
112
  end
113
113
 
@@ -115,39 +115,34 @@ describe JenkinsPipelineBuilder::Compiler do
115
115
  it 'generates correct new jobs with true' do
116
116
  item = { enabled: '{{use1}}', parameters: { rootPom: 'path_to_pomasd' } }
117
117
  settings = { name: 'PushTest', description: 'DB Pipeline tooling', git_repo: 'git@github.roving.com:devops/DBPipeline.git', git_branch: 'master', excluded_user: 'buildmaster', hipchat_room: 'CD Builds', hipchat_auth_token: 'f3e98ed54605b36f56dd2c562e3775', discard_days: '30', discard_number: '100', maven_name: 'tools-maven-3.0.3', hipchat_jenkins_url: 'https://cd-jenkins.ad.prodcc.net/', use1: true }
118
- success, item = compiler.handle_enable(item, settings)
119
- expect(success).to be true
118
+ item = compiler.handle_enable(item, settings)
120
119
  expect(item).to eq(rootPom: 'path_to_pomasd')
121
120
  end
122
121
 
123
122
  it 'generates correct new jobs when the params are a string' do
124
123
  item = { enabled: '{{use1}}', parameters: 'path_to_pomasd' }
125
124
  settings = { name: 'PushTest', description: 'DB Pipeline tooling', git_repo: 'git@github.roving.com:devops/DBPipeline.git', git_branch: 'master', excluded_user: 'buildmaster', hipchat_room: 'CD Builds', hipchat_auth_token: 'f3e98ed54605b36f56dd2c562e3775', discard_days: '30', discard_number: '100', maven_name: 'tools-maven-3.0.3', hipchat_jenkins_url: 'https://cd-jenkins.ad.prodcc.net/', use1: true }
126
- success, item = compiler.handle_enable(item, settings)
127
- expect(success).to be true
125
+ item = compiler.handle_enable(item, settings)
128
126
  expect(item).to eq('path_to_pomasd')
129
127
  end
130
128
 
131
129
  it 'generates correct new jobs with false' do
132
130
  item = { enabled: '{{use1}}', parameters: { rootPom: 'path_to_pomasd' } }
133
131
  settings = { name: 'PushTest', description: 'DB Pipeline tooling', git_repo: 'git@github.roving.com:devops/DBPipeline.git', git_branch: 'master', excluded_user: 'buildmaster', hipchat_room: 'CD Builds', hipchat_auth_token: 'f3e98ed54605b36f56dd2c562e3775', discard_days: '30', discard_number: '100', maven_name: 'tools-maven-3.0.3', hipchat_jenkins_url: 'https://cd-jenkins.ad.prodcc.net/', use1: false }
134
- success, item = compiler.handle_enable(item, settings)
135
- expect(success).to be true
132
+ item = compiler.handle_enable(item, settings)
136
133
  expect(item).to eq({})
137
134
  end
138
135
 
139
136
  it 'fails when value not found' do
140
137
  item = { enabled: '{{use_fail}}', parameters: { rootPom: 'path_to_pomasd' } }
141
138
  settings = { name: 'PushTest', description: 'DB Pipeline tooling', git_repo: 'git@github.roving.com:devops/DBPipeline.git', git_branch: 'master', excluded_user: 'buildmaster', hipchat_room: 'CD Builds', hipchat_auth_token: 'f3e98ed54605b36f56dd2c562e3775', discard_days: '30', discard_number: '100', maven_name: 'tools-maven-3.0.3', hipchat_jenkins_url: 'https://cd-jenkins.ad.prodcc.net/', use1: true }
142
- success, _item = compiler.handle_enable(item, settings)
143
- expect(success).to be false
139
+ expect { compiler.handle_enable(item, settings) }.to raise_error(/Could not find defined substitution variable: use_fail/)
144
140
  end
145
141
 
146
142
  it 'removes empty builders' do
147
143
  item = { enabled: '{{use}}', parameters: { rootPom: 'one' } }
148
144
  settings = { name: 'PushTest', description: 'DB Pipeline tooling', git_repo: 'git@github.roving.com:devops/DBPipeline.git', git_branch: 'master', excluded_user: 'buildmaster', hipchat_room: 'CD Builds', hipchat_auth_token: 'f3e98ed54605b36f56dd2c562e3775', discard_days: '30', discard_number: '100', maven_name: 'tools-maven-3.0.3', hipchat_jenkins_url: 'https://cd-jenkins.ad.prodcc.net/', use: false }
149
- success, result = compiler.handle_enable(item, settings)
150
- expect(success).to be true
145
+ result = compiler.handle_enable(item, settings)
151
146
  expect(result).to eq({})
152
147
  end
153
148
  end
@@ -9,7 +9,7 @@ WRAPPERS = {
9
9
  rvm: ['0', '0.5'],
10
10
  timestamp: ['0'],
11
11
  xvfb: ['0']
12
- }
12
+ }.freeze
13
13
  PUBLISHERS = {
14
14
  archive_artifact: ['0'],
15
15
  brakeman: ['0'],
@@ -30,7 +30,7 @@ PUBLISHERS = {
30
30
  publish_tap_results: ['0'],
31
31
  sonar_result: ['0'],
32
32
  xunit: ['0']
33
- }
33
+ }.freeze
34
34
  BUILDERS = {
35
35
  blocking_downstream: ['0'],
36
36
  copy_artifact: ['0'],
@@ -40,14 +40,16 @@ BUILDERS = {
40
40
  remote_job: ['0'],
41
41
  shell_command: ['0'],
42
42
  checkmarx_scan: ['0'],
43
- system_groovy: ['0']
44
- }
43
+ system_groovy: ['0'],
44
+ sonar_standalone: ['0']
45
+
46
+ }.freeze
45
47
  TRIGGERS = {
46
48
  git_push: ['0'],
47
49
  periodic_build: ['0'],
48
50
  scm_polling: ['0'],
49
51
  upstream: ['0']
50
- }
52
+ }.freeze
51
53
  JOB_ATTRIBUTES = {
52
54
  concurrent_build: ['0'],
53
55
  description: ['0'],
@@ -62,7 +64,7 @@ JOB_ATTRIBUTES = {
62
64
  promoted_builds: ['0'],
63
65
  scm_params: ['0', '2.0'],
64
66
  throttle: ['0']
65
- }
67
+ }.freeze
66
68
 
67
69
  describe 'built in extensions' do
68
70
  before :each do
@@ -0,0 +1,15 @@
1
+ [
2
+ {
3
+ "defaults": {
4
+ "name": "global",
5
+ "description": "Tests, all the tests"
6
+ }
7
+ },
8
+ {
9
+ "project": {
10
+ "name": "TestProject",
11
+ "jobs": [
12
+ "{{name}}-part1"
13
+ ]
14
+ }
15
+ ]
@@ -0,0 +1,10 @@
1
+ [
2
+ {
3
+ "view": {
4
+ "name": "{{name}} View",
5
+ "type": "listview",
6
+ "description": "{{description}}",
7
+ "regex": "{{name}}.*"
8
+ }
9
+ }
10
+ ]
@@ -0,0 +1,8 @@
1
+ - defaults:
2
+ name: global
3
+ description: 'Tests, all the tests'
4
+
5
+ - project:
6
+ name: BadTestProject
7
+ jobs:
8
+ - '{{name}}-part1'
@@ -0,0 +1,5 @@
1
+ - view:
2
+ name: '{{name}} View'
3
+ type: 'listview'
4
+ description: '{{description}}'
5
+ regex: '{{name}}.*'
@@ -174,7 +174,7 @@ describe JenkinsPipelineBuilder::Generator do
174
174
  git_repo_name: 'generator_tests'))
175
175
  .and_return(pr_generator)
176
176
  expect(pr_generator).to receive(:delete_closed_prs)
177
- pr_generator.stub(:convert!) do |job_collection, pr|
177
+ allow(pr_generator).to receive(:convert!) do |job_collection, pr|
178
178
  job_collection.defaults[:value][:application_name] = "testapp-PR#{pr}"
179
179
  end
180
180
  expect(pr_generator).to receive(:open_prs).and_return [1, 2]
@@ -210,6 +210,19 @@ describe JenkinsPipelineBuilder::Generator do
210
210
  path = File.expand_path('../fixtures/generator_tests/test_combo_files', __FILE__)
211
211
  @generator.job_collection.load_from_path path
212
212
  end
213
+
214
+ it 'errors when reading a bad yaml file' do
215
+ path = File.expand_path('../fixtures/generator_tests/test_bad_yaml_files', __FILE__)
216
+ expect { @generator.job_collection.load_from_path path }.to raise_error(
217
+ RuntimeError, /There was an error while parsing a file/
218
+ )
219
+ end
220
+ it 'errors when reading a bad json file' do
221
+ path = File.expand_path('../fixtures/generator_tests/test_bad_json_files', __FILE__)
222
+ expect { @generator.job_collection.load_from_path path }.to raise_error(
223
+ RuntimeError, /There was an error while parsing a file/
224
+ )
225
+ end
213
226
  end
214
227
 
215
228
  describe '#dump' do
@@ -224,7 +237,7 @@ describe JenkinsPipelineBuilder::Generator do
224
237
  end
225
238
  end
226
239
  stub_request(:get, 'http://username:password@127.0.0.1:8080/job/test_job/config.xml')
227
- .to_return(status: 200, body: "#{body}", headers: {})
240
+ .to_return(status: 200, body: body.to_s, headers: {})
228
241
  @generator.dump(job_name)
229
242
  expect(File.exist?("#{job_name}.xml")).to be true
230
243
  File.delete("#{job_name}.xml")
@@ -234,7 +247,7 @@ describe JenkinsPipelineBuilder::Generator do
234
247
  describe '#projects' do
235
248
  it 'returns a list of projects' do
236
249
  path = File.expand_path('../fixtures/generator_tests/multi_project', __FILE__)
237
- expect(@generator.projects path).to eq %w(SamplePipeline1 SamplePipeline2 SamplePipeline3)
250
+ expect(@generator.projects(path)).to eq %w(SamplePipeline1 SamplePipeline2 SamplePipeline3)
238
251
  end
239
252
  end
240
253
 
@@ -243,6 +256,13 @@ describe JenkinsPipelineBuilder::Generator do
243
256
  allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
244
257
  list_installed: { 'description' => '20.0', 'git' => '20.0' })
245
258
  end
259
+ after :each do
260
+ file_paths = ['out/xml/TemplatePipeline-10.xml',
261
+ 'out/xml/TemplatePipeline-11.xml']
262
+ file_paths.each do |file_path|
263
+ File.delete(file_path) if File.exist?(file_path)
264
+ end
265
+ end
246
266
  it 'generates xml and saves to disk without sending jobs to the server' do
247
267
  job_name = 'TemplatePipeline'
248
268
  path = File.expand_path('../fixtures/generator_tests/template_pipeline', __FILE__)
@@ -96,7 +96,7 @@ describe JenkinsPipelineBuilder::ModuleRegistry do
96
96
  end
97
97
 
98
98
  it 'calls the xml block when executing the item' do
99
- @ext.xml -> (_) { fail XmlException, 'foo' }
99
+ @ext.xml -> (_) { raise XmlException, 'foo' }
100
100
 
101
101
  expect do
102
102
  JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
@@ -104,7 +104,7 @@ describe JenkinsPipelineBuilder::ModuleRegistry do
104
104
  end
105
105
 
106
106
  it 'calls the before block' do
107
- @ext.before -> (_) { fail BeforeException, 'foo' }
107
+ @ext.before -> (_) { raise BeforeException, 'foo' }
108
108
 
109
109
  expect do
110
110
  JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
@@ -112,7 +112,7 @@ describe JenkinsPipelineBuilder::ModuleRegistry do
112
112
  end
113
113
 
114
114
  it 'calls the after block' do
115
- @ext.after -> (_) { fail AfterException, 'foo' }
115
+ @ext.after -> (_) { raise AfterException, 'foo' }
116
116
 
117
117
  expect do
118
118
  JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
@@ -132,7 +132,7 @@ describe JenkinsPipelineBuilder::ModuleRegistry do
132
132
  plugin_id 'unorderedTest'
133
133
 
134
134
  before do
135
- fail BeforeException, 'foo'
135
+ raise BeforeException, 'foo'
136
136
  end
137
137
 
138
138
  xml do
@@ -154,7 +154,7 @@ describe JenkinsPipelineBuilder::ModuleRegistry do
154
154
  plugin_id 'unorderedTest'
155
155
 
156
156
  after do
157
- fail AfterException, 'foo'
157
+ raise AfterException, 'foo'
158
158
  end
159
159
 
160
160
  xml do
@@ -176,7 +176,7 @@ describe JenkinsPipelineBuilder::ModuleRegistry do
176
176
  plugin_id 'unorderedTest'
177
177
 
178
178
  xml do
179
- fail XmlException, 'foo'
179
+ raise XmlException, 'foo'
180
180
  end
181
181
 
182
182
  after do
@@ -82,25 +82,28 @@ describe JenkinsPipelineBuilder::PullRequestGenerator do
82
82
  end
83
83
 
84
84
  context '#convert!' do
85
- it 'converts the job application name' do
85
+ before(:each) do
86
86
  stub_request(:get, url)
87
87
  .with(headers: { 'Accept' => '*/*',
88
88
  'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
89
89
  'Host' => 'github.com',
90
90
  'User-Agent' => 'Ruby' })
91
91
  .to_return(status: 200, body: open_prs_json, headers: {})
92
+ end
93
+
94
+ it 'converts the job application name' do
92
95
  collection = job_collection.clone
93
96
  subject.convert! collection, 8
94
97
  expect(collection.defaults[:value][:application_name]).to eq "#{application_name}-PR8"
95
98
  end
96
99
 
100
+ it 'provides the PR number to the job settings' do
101
+ collection = job_collection.clone
102
+ subject.convert! collection, 8
103
+ expect(collection.defaults[:value][:pull_request_number]).to eq '8'
104
+ end
105
+
97
106
  it 'overrides the git params' do
98
- stub_request(:get, url)
99
- .with(headers: { 'Accept' => '*/*',
100
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
101
- 'Host' => 'github.com',
102
- 'User-Agent' => 'Ruby' })
103
- .to_return(status: 200, body: open_prs_json, headers: {})
104
107
  pr = 8
105
108
  collection = job_collection.clone
106
109
  subject.convert! collection, pr
@@ -115,12 +118,6 @@ describe JenkinsPipelineBuilder::PullRequestGenerator do
115
118
  end
116
119
 
117
120
  it 'does not override extra params' do
118
- stub_request(:get, url)
119
- .with(headers: { 'Accept' => '*/*',
120
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
121
- 'Host' => 'github.com',
122
- 'User-Agent' => 'Ruby' })
123
- .to_return(status: 200, body: open_prs_json, headers: {})
124
121
  pr = 8
125
122
  collection = job_collection.clone
126
123
  subject.convert! collection, pr
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins_pipeline_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.4
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Moochnick
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-07 00:00:00.000000000 Z
12
+ date: 2016-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -166,7 +166,7 @@ dependencies:
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  - !ruby/object:Gem::Dependency
169
- name: pry
169
+ name: byebug
170
170
  requirement: !ruby/object:Gem::Requirement
171
171
  requirements:
172
172
  - - ! '>='
@@ -412,6 +412,10 @@ files:
412
412
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/template_pipeline/project.yaml
413
413
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/template_pipeline_nested/jobs.tar.gz
414
414
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/template_pipeline_nested/project.yaml
415
+ - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_json_files/project.json
416
+ - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_json_files/view.json
417
+ - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_yaml_files/project.yaml
418
+ - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_yaml_files/view.yaml
415
419
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_combo_files/project.json
416
420
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_combo_files/view.yaml
417
421
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_job.xml
@@ -455,7 +459,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
455
459
  version: '0'
456
460
  requirements: []
457
461
  rubyforge_project:
458
- rubygems_version: 2.4.5
462
+ rubygems_version: 2.5.1
459
463
  signing_key:
460
464
  specification_version: 4
461
465
  summary: This gem is will boostrap your Jenkins pipelines
@@ -494,6 +498,10 @@ test_files:
494
498
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/template_pipeline/project.yaml
495
499
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/template_pipeline_nested/jobs.tar.gz
496
500
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/template_pipeline_nested/project.yaml
501
+ - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_json_files/project.json
502
+ - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_json_files/view.json
503
+ - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_yaml_files/project.yaml
504
+ - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_bad_yaml_files/view.yaml
497
505
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_combo_files/project.json
498
506
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_combo_files/view.yaml
499
507
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_job.xml