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

Commit

Permalink
integration spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Park committed Jul 17, 2014
1 parent b2933f9 commit 5ba8731
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 42 deletions.
5 changes: 1 addition & 4 deletions commit_build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/bin/bash
bundle --version || gem install bundler --no-ri --no-rdoc
bundle install
rm -f *.gem
bundle exec rake spec || exit $?
bundle exec gem build jenkins_pipeline_builder.gemspec || exit $?
bundle exec gem bump
bundle exec rake spec || exit $?
68 changes: 36 additions & 32 deletions lib/jenkins_pipeline_builder/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ def view
JenkinsPipelineBuilder::View.new(self)
end

def bootstrap(path, project_name)
@logger.info "Bootstrapping pipeline from path #{path}"
def bootstrap(path, project_name = nil)
logger.info "Bootstrapping pipeline from path #{path}"
load_collection_from_path(path)
# @logger.info @job_collection
cleanup_temp_remote
load_extensions(path)
errors = {}
Expand All @@ -79,22 +78,22 @@ def bootstrap(path, project_name)
errors = publish_jobs(jobs)
end
errors.each do |k, v|
@logger.error "Encountered errors compiling: #{k}:"
@logger.error v
logger.error "Encountered errors compiling: #{k}:"
logger.error v
end
errors
end

def pull_request(path, project_name)
success = false
@logger.info "Pull Request Generator Running from path #{path}"
logger.info "Pull Request Generator Running from path #{path}"
load_collection_from_path(path)
cleanup_temp_remote
load_extensions(path)
@logger.info "Project: #{projects}"
logger.info "Project: #{projects}"
projects.each do |project|
next unless project[:name] == project_name || project_name.nil?
@logger.info "Using Project #{project}"
logger.info "Using Project #{project}"
pull_job = find_pull_request_generator(project)
p_success, p_payload = compile_pull_request_generator(pull_job[:name], project)
next unless p_success
Expand Down Expand Up @@ -210,7 +209,7 @@ def load_job_collection(yaml, remote = false)
fail "Duplicate item with name '#{name}' was detected."
end
else
@job_collection[name.to_s] = { name: name.to_s, type: key, value: value }
@job_collection[name.to_s] = {name: name.to_s, type: key, value: value}
end
end
end
Expand Down Expand Up @@ -328,7 +327,7 @@ def list_plugins

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

Expand All @@ -346,7 +345,7 @@ def process_job_changes(jobs)

def process_views(views, project, errors = {})
views.map! do |view|
view.is_a?(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 @@ -386,7 +385,7 @@ def resolve_project(project)
logger.info project
process_job_changes(jobs)
errors = process_jobs(jobs, project)
errors = process_views(project_body[:views], project, errors) if project_body[:views]
errors = process_views(project_body[:views], project, errors) if project_body[:views]
errors.each do |k, v|
puts "Encountered errors processing: #{k}:"
v.each do |key, error|
Expand Down Expand Up @@ -429,7 +428,7 @@ def publish_project(project_name, errors = {})
next unless project_name.nil? || project[:name] == project_name
success, payload = resolve_project(project)
if success
@logger.info 'successfully resolved project'
logger.info 'successfully resolved project'
compiled_project = payload
else
return false
Expand All @@ -447,7 +446,7 @@ def publish_project(project_name, errors = {})

def publish_jobs(jobs, errors = {})
jobs.each do |i|
@logger.info "Processing #{i}"
logger.info "Processing #{i}"
job = i[:result]
fail "Result is empty for #{i}" if job.nil?
success, payload = compile_job_to_xml(job)
Expand All @@ -465,7 +464,8 @@ def create_or_update(job, xml)
if @debug
logger.info "Will create job #{job}"
logger.info "#{xml}"
File.open(job_name + '.xml', 'w') { |f| f.write xml }
Dir.mkdir(out_dir) unless File.exists?(out_dir)
File.open("#{out_dir}/#{job_name}.xml", 'w') { |f| f.write xml }
return
end

Expand All @@ -482,19 +482,19 @@ def compile_job_to_xml(job)
logger.info "Creating Yaml Job #{job}"
job[:job_type] = 'free_style' unless job[:job_type]
case job[:job_type]
when 'job_dsl'
xml = compile_freestyle_job_to_xml(job)
payload = update_job_dsl(job, xml)
when 'multi_project'
xml = compile_freestyle_job_to_xml(job)
payload = adjust_multi_project xml
when 'build_flow'
xml = compile_freestyle_job_to_xml(job)
payload = add_job_dsl(job, xml)
when 'free_style', 'pull_request_generator'
payload = compile_freestyle_job_to_xml job
else
return false, "Job type: #{job[:job_type]} is not one of job_dsl, multi_project, build_flow or free_style"
when 'job_dsl'
xml = compile_freestyle_job_to_xml(job)
payload = update_job_dsl(job, xml)
when 'multi_project'
xml = compile_freestyle_job_to_xml(job)
payload = adjust_multi_project xml
when 'build_flow'
xml = compile_freestyle_job_to_xml(job)
payload = add_job_dsl(job, xml)
when 'free_style', 'pull_request_generator'
payload = compile_freestyle_job_to_xml job
else
return false, "Job type: #{job[:job_type]} is not one of job_dsl, multi_project, build_flow or free_style"
end

[true, payload]
Expand All @@ -518,7 +518,7 @@ def compile_freestyle_job_to_xml(params)
puts "Template merged: #{template}"
end

xml = client.job.build_freestyle_config(params)
xml = client.job.build_freestyle_config(params)
n_xml = Nokogiri::XML(xml)

logger.debug 'Loading the required modules'
Expand All @@ -539,7 +539,7 @@ def add_job_dsl(job, xml)

# TODO: make sure this is tested
def update_job_dsl(job, xml)
n_xml = Nokogiri::XML(xml)
n_xml = Nokogiri::XML(xml)
n_builders = n_xml.xpath('//builders').first
Nokogiri::XML::Builder.with(n_builders) do |b_xml|
build_job_dsl(job, b_xml)
Expand All @@ -554,11 +554,11 @@ def generate_job_dsl_body(params)

n_xml = Nokogiri::XML(xml)
if n_xml.xpath('//javaposse.jobdsl.plugin.ExecuteDslScripts').empty?
p_xml = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |b_xml|
p_xml = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |b_xml|
build_job_dsl(params, b_xml)
end

n_xml.xpath('//builders').first.add_child("\r\n" + p_xml.doc.root.to_xml(indent: 4) + "\r\n")
n_xml.xpath('//builders').first.add_child("\r\n" + p_xml.doc.root.to_xml(indent: 4) + "\r\n")
xml = n_xml.to_xml
end
xml
Expand All @@ -577,5 +577,9 @@ def build_job_dsl(job, xml)
xml.removedJobAction 'IGNORE'
end
end

def out_dir
'out/xml'
end
end
end
8 changes: 2 additions & 6 deletions pipeline/Jenkins-Pipeline-Builder.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- job:
name: 'Jenkins-Pipeline-Builder'
name: '{{name}}-Commit'
scm_provider: git
scm_url: https://github.com/constantcontact/jenkins_pipeline_builder.git
scm_branch: master
Expand All @@ -11,14 +11,10 @@
wrappers:
- timestamp: true
- ansicolor: true
- rvm: "`cat .ruby-version`@`cat .ruby-gemset`"
- rvm: "`cat .ruby-version`"
publishers:
- junit_result:
test_results: 'out/**/*.xml'
- git:
push-merge: true
push-only-if-success: false
- hipchat: true
- coverage_result:
report_dir: out/coverage/rcov
total:
Expand Down
10 changes: 10 additions & 0 deletions pipeline/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- project:
name: Jenkins-Pipeline-Builder
description: 'Do not edit this job through the web!'
git_repo: [email protected]:constantcontact/jenkins_pipeline_builder.git
git_branch: master
discard_days: '30'
discard_number: '100'
rvm: '`cat .ruby-version`'
jobs:
- '{{name}}-Commit'
22 changes: 22 additions & 0 deletions spec/requests/pipeline_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require File.expand_path('../../lib/jenkins_pipeline_builder/spec_helper', __FILE__)

describe 'Pipeline' do
before :all do
JenkinsPipelineBuilder.credentials = {
server_ip: '127.0.0.1',
server_port: 8080,
username: 'username',
password: 'password',
log_location: '/dev/null'
}
end

let(:generator) {JenkinsPipelineBuilder::Generator.new}

it 'generates its own pipeline' do
generator.debug = true
generator.bootstrap './pipeline'


end
end

0 comments on commit 5ba8731

Please sign in to comment.