Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'brgaulin/master' into extensions
Browse files Browse the repository at this point in the history
Conflicts:
	lib/jenkins_pipeline_builder/extendable.rb
	lib/jenkins_pipeline_builder/generator.rb
	lib/jenkins_pipeline_builder/module_registry.rb
	spec/unit_tests/generator_spec.rb
	spec/unit_tests/module_registry_spec.rb
  • Loading branch information
Joseph Henrich committed Jul 1, 2014
2 parents 56556da + 37b2283 commit 6e0be9b
Show file tree
Hide file tree
Showing 56 changed files with 54 additions and 1,465 deletions.
10 changes: 5 additions & 5 deletions jenkins_pipeline_builder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
spec.version = JenkinsPipelineBuilder::VERSION
spec.authors = ['Igor Moochnick', 'Joseph Henrich']
spec.email = %w([email protected] [email protected])
spec.description = %q(This is a simple and easy-to-use Jenkins Pipeline generator with features focused on
automating Job & Pipeline creation from the YAML files checked-in with your application source code)
spec.summary = %q(This gem is will boostrap your Jenkins pipelines)
spec.description = 'This is a simple and easy-to-use Jenkins Pipeline generator with features focused on
automating Job & Pipeline creation from the YAML files checked-in with your application source code'
spec.summary = 'This gem is will boostrap your Jenkins pipelines'
spec.homepage = 'https://github.com/ConstantContact/jenkins_pipeline_builder'
spec.license = 'MIT'

Expand All @@ -21,8 +21,8 @@ automating Job & Pipeline creation from the YAML files checked-in with your appl

ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES'] = 'true'

spec.add_dependency 'nokogiri', '~> 1.5.0'
spec.add_dependency 'jenkins_api_client', '~> 0.14.1'
spec.add_dependency 'nokogiri', '~> 1.6.0'
spec.add_dependency 'jenkins_api_client', '~> 1.0.0'
spec.add_dependency 'thor', '>= 0.18.0'
spec.add_dependency 'activesupport'
spec.add_dependency 'archive-tar-minitar'
Expand Down
4 changes: 2 additions & 2 deletions lib/jenkins_pipeline_builder/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def self.resolve_value(value, settings, job_collection)
def self.get_settings_bag(item_bag, settings_bag = {})
item = item_bag[:value]
bag = {}
return unless item.kind_of?(Hash)
return unless item.is_a?(Hash)
item.keys.each do |k|
val = item[k]
if val.kind_of? String
if val.is_a? String
new_value = resolve_value(val, settings_bag, {})
return nil if new_value.nil?
bag[k] = new_value
Expand Down
51 changes: 44 additions & 7 deletions lib/jenkins_pipeline_builder/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def get_item(name)
def load_extensions(path)
path = "#{path}/extensions"
path = File.expand_path(path, Dir.getwd)

return unless File.directory?(path)

@logger.info "Loading extensions from folder #{path}"
Expand All @@ -125,6 +124,38 @@ def load_extensions(path)
@logger.info "Loaded #{file}"
require file
end
match_extension_versions
end

def match_extension_versions
registry = @module_registry.registry[:job]
installed_plugins = @debug ? nil : list_plugins # Only get plugins if not in debug mode
@logger.debug 'Loading newest version of all plugins since we are in debug mode.'
registry.each do |registry_key, registry_value|
if registry_value[:registry]
registry_value[:registry].each do |extension_key, extension_value|
registry[registry_key][:registry][extension_key] = newest_compatible({ extension_key => extension_value }, installed_plugins, registry_key)
end
else
registry[registry_key] = newest_compatible({ registry_key => registry_value }, installed_plugins)
end
end
end

def newest_compatible(extension, installed_plugins, key = nil)
# Fetch the registrered_modules for the extension
registry = @module_registry.registered_modules
registry = key.nil? ? registry[:job_attributes] : registry[key]
registry = registry[extension.keys.first]
extension = extension.first[1]
keep = nil
keep_version = ''
extension.each do |version, block|
is_available = @debug ? true : version.to_s <= installed_plugins[registry[:plugin_id].to_s].to_s
is_newer = version.to_s >= keep_version
keep = block if keep.nil? || (is_available && is_newer)
end
keep
end

def load_template(path, template)
Expand Down Expand Up @@ -221,24 +252,30 @@ def cleanup_temp_remote
end
end

def list_plugins
client.plugin.list_installed
end

def prepare_jobs(jobs)
jobs.map! do |job|
job.kind_of?(String) ? { job.to_sym => {} } : job
job.is_a?(String) ? { job.to_sym => {} } : job
end
end

def process_job_changes(jobs)
jobs.each do |job|
job_id = job.keys.first
j = get_item(job_id)
Utils.hash_merge!(j, job[job_id])
j[:value][:name] = j[:job_name] if j[:job_name]
if j
Utils.hash_merge!(j, job[job_id])
j[:value][:name] = j[:job_name] if j[:job_name]
end
end
end

def process_views(views, project, errors = {})
views.map! do |view|
view.kind_of?(String) ? { view.to_sym => {} } : view
view.is_a?(String) ? { view.to_sym => {} } : view
end
views.each do |view|
view_id = view.keys.first
Expand Down Expand Up @@ -416,9 +453,9 @@ def pull_request(path, project_name)
end
# Purge old jobs
pull.purge.each do |job|
jobs = @client.job.list "#{job}.*"
jobs = client.job.list "#{job}.*"
jobs.each do |job|
@client.job.delete job
client.job.delete job
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions lib/jenkins_pipeline_builder/module_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ module JenkinsPipelineBuilder
class ModuleRegistry
attr_accessor :registry, :registered_modules
def initialize
@registry = {
job: {
}
}
@registry = { job: {} }
end

# Ideally refactor this out to be derived from the registry,
Expand Down
4 changes: 2 additions & 2 deletions lib/jenkins_pipeline_builder/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def deep_merge(second)
class Utils
# Code was duplicated from jeknins_api_client
def self.symbolize_keys_deep!(h)
return unless h.kind_of?(Hash)
return unless h.is_a?(Hash)
h.keys.each do |k|
ks = k.respond_to?(:to_sym) ? k.to_sym : k
h[ks] = h.delete k # Preserve order even when k == ks
symbolize_keys_deep! h[ks] if h[ks].kind_of? Hash
symbolize_keys_deep! h[ks] if h[ks].is_a? Hash
h[ks].each { |item| symbolize_keys_deep!(item) } if h[ks].is_a?(Array)
end
end
Expand Down
57 changes: 0 additions & 57 deletions spec/unit_tests/fixtures/files/Job-Build-Flow.xml

This file was deleted.

22 changes: 0 additions & 22 deletions spec/unit_tests/fixtures/files/Job-Build-Flow.yaml

This file was deleted.

129 changes: 0 additions & 129 deletions spec/unit_tests/fixtures/files/Job-Build-Maven.xml

This file was deleted.

31 changes: 0 additions & 31 deletions spec/unit_tests/fixtures/files/Job-Build-Maven.yaml

This file was deleted.

Loading

0 comments on commit 6e0be9b

Please sign in to comment.