Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Create options for skipping plugins in <publishers> tag #4

Merged
merged 2 commits into from

3 participants

Anton Bangratz Armin Schreger Andreas Tiefenthaler
Anton Bangratz

If you extend the config (file) by an array of 'skip_plugins' entries, it will try to remove those from the XML configuration template.

Example:

...
  skip_plugins:
    - test
    - parameterizedtrigger.BuildTrigger
    - rubyMetrics.railsStats.RailsStatsPublisher
...

If those options are not given or the XML template misses the <publishers>...</publishers> section, the action will be silently skipped.

No version stuff has been harmed with this pull request.

:wink:

Andreas Tiefenthaler pxlpnk merged commit 18935bb into from
Armin Schreger

:+1: if you deploy it

Armin Schreger

:+1: if we build a config to skip feature branches to deploy on master

Armin Schreger

@pxlpnk: Is it possible to test this on my local dev machine? I really would like to fix the bug (every feature branch deploys on master).
We really use feature branches in our daily workflow.

Andreas Tiefenthaler
Owner

@armins of course.
You either let the Kraken run locally on your dev machine and work with the production install of your Jenkins
or you reproduce the complete setup locally (Inkluding jenkins and some repositories with branches)

Andreas Tiefenthaler pxlpnk was assigned
Armin Schreger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 17, 2012
  1. Anton Bangratz

    Add kraken-build spec

    abangratz authored
  2. Anton Bangratz
This page is out of date. Refresh to see the latest.
17 lib/kraken-build/jenkins-api.rb
View
@@ -1,6 +1,8 @@
class JenkinsApi
include HTTParty
+ attr_accessor :skip_plugins
+
def initialize(options = {})
if options[:port]
self.class.base_uri "#{options[:host]}:#{options[:port]}"
@@ -8,9 +10,14 @@ def initialize(options = {})
self.class.base_uri options[:host]
end
- if(options[:username] && options[:password])
+ if (options[:username] && options[:password])
self.class.basic_auth options[:username] , options[:password]
end
+ if (options[:skip_plugins])
+ self.skip_plugins = options[:skip_plugins]
+ else
+ self.skip_plugins = []
+ end
end
def get_jobs(options = {})
@@ -35,6 +42,14 @@ def create_job_configuration(repo, branch)
doc = REXML::Document.new(draft)
REXML::XPath.first(doc, '//branches//hudson.plugins.git.BranchSpec//name').text = branch
+ plugin_names = self.skip_plugins.map { |n| "hudson.plugins.#{n}" }
+ publishers = REXML::XPath.first(doc, '//project/publishers')
+ if publishers && publishers.has_elements? && self.skip_plugins && !(self.skip_plugins.empty?)
+ publishers.children.select { |child| child.xpath.match %r[/hudson\.plugins] }.each do |plugin|
+ doc.delete_element(plugin.xpath) if plugin_names.any? { |name| plugin.xpath[name]}
+ end
+ end
+
doc.to_s
end
56 spec/lib/jenkins_api_spec.rb
View
@@ -27,13 +27,17 @@
api.class.default_options[:base_uri].should == 'http://host:1337'
end
+ it "sets the plugins to skip at initialization" do
+ options = {:skip_plugins => ['test'] }
+ jenkins_api = JenkinsApi.new(options)
+ jenkins_api.skip_plugins.should eq(['test'])
+ end
+
end
context "when interacting with Jenkins" do
- before(:each) do
- @api = JenkinsApi.new
- end
+ let(:api) { JenkinsApi.new }
it "#get_jobs returns an array of jobs" do
j = []
@@ -42,9 +46,9 @@
results = {"jobs" => j}
- @api.class.should_receive(:get).and_return(results)
+ api.class.should_receive(:get).and_return(results)
- jobs = @api.get_jobs
+ jobs = api.get_jobs
jobs.should include "Foo"
jobs.should include "Bar"
@@ -53,15 +57,15 @@
it "#remove_job returns true if a job was deleted successfully" do
job_name = "foo.test_branch"
- @api.class.should_receive(:post).with("/job/#{CGI.escape(job_name)}/doDelete").and_return(true)
+ api.class.should_receive(:post).with("/job/#{CGI.escape(job_name)}/doDelete").and_return(true)
- @api.remove_job(job_name)
+ api.remove_job(job_name)
end
it "#build_job returns true and triggers a build for a job" do
- @api.class.should_receive(:get).with("/job/FooJob/build").and_return(true)
+ api.class.should_receive(:get).with("/job/FooJob/build").and_return(true)
- @api.build_job("FooJob")
+ api.build_job("FooJob")
end
it "#get_job_configuration returns the xml configuration for a job" do
@@ -71,19 +75,33 @@
xml = double()
xml.should_receive(:body).and_return(a)
- @api.class.should_receive(:get).with("/job/FooJob/config.xml", {}).and_return(xml)
+ api.class.should_receive(:get).with("/job/FooJob/config.xml", {}).and_return(xml)
- @api.get_job_configuration("FooJob").should be(a)
+ api.get_job_configuration("FooJob").should be(a)
end
-
- it "#create_job_configuration returns a valid job configuration" do
- xml = <<-XML
+ context "#create_job_configuration" do
+ it "returns a valid job configuration" do
+ xml = <<-XML
<xml><branches><hudson.plugins.git.BranchSpec><name>master</name></hudson.plugins.git.BranchSpec></branches></xml>
- XML
- xml.should_receive(:body).and_return(xml)
- @api.class.should_receive(:get).with('/job/foobar.master/config.xml', {}).and_return(xml)
- @api.create_job_configuration('foobar', 'feature').should =~ /feature/
- end
+ XML
+ xml.should_receive(:body).and_return(xml)
+ api.class.should_receive(:get).with('/job/foobar.master/config.xml', {}).and_return(xml)
+ api.create_job_configuration('foobar', 'feature').should =~ /feature/
+ end
+ it "removes all plugins that have been listed in 'skip_plugins'" do
+ api.skip_plugins = ['test']
+ xml_stripped = <<-XML_S
+<xml><project><branches><hudson.plugins.git.BranchSpec><name>master</name></hudson.plugins.git.BranchSpec></branches><publishers></publishers></project></xml>
+ XML_S
+ xml = <<-XML
+<xml><project><branches><hudson.plugins.git.BranchSpec><name>master</name></hudson.plugins.git.BranchSpec></branches><publishers><hudson.plugins.test>test</hudson.plugins.test></publishers></project></xml>
+ XML
+ xml.should_receive(:body).and_return(xml)
+ api.class.should_receive(:get).with('/job/foobar.master/config.xml', {}).and_return(xml)
+ api.create_job_configuration('foobar', 'feature').should_not =~ /hudson\.plugins\.test/
+ end
+ end
+
end
38 spec/lib/kraken-build_spec.rb
View
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe KrakenBuild do
+ context "Setting config" do
+ let(:options) { mock(Hash).as_null_object }
+
+ it "sets the config options at @config" do
+ kraken = KrakenBuild.set_config(options)
+ KrakenBuild.instance_variable_get(:@config).should eq(options)
+ end
+
+ it "sets the repository option as @repository" do
+ repository = mock(String)
+ options.should_receive(:[]).with(:repository).and_return(repository)
+ kraken = KrakenBuild.set_config(options)
+ KrakenBuild.instance_variable_get(:@repository).should eq(repository)
+ end
+
+ it "sets the github api from instance call" do
+ github_api = mock(GithubApi).as_null_object
+ GithubApi.should_receive(:new).and_return(github_api)
+ kraken = KrakenBuild.set_config(options)
+ KrakenBuild.instance_variable_get(:@github).should eq(github_api)
+ end
+ it "sets the jenkins api from instance call" do
+ jenkins_api = mock(GithubApi).as_null_object
+ JenkinsApi.should_receive(:new).and_return(jenkins_api)
+ kraken = KrakenBuild.set_config(options)
+ KrakenBuild.instance_variable_get(:@jenkins).should eq(jenkins_api)
+ end
+ it "returns the config" do
+ kraken = KrakenBuild.set_config(options)
+ KrakenBuild.instance_variable_get(:@config).should eq(options)
+ kraken.should eq(options)
+ end
+
+ end
+end
Something went wrong with that request. Please try again.