From 60be683cede954da6e5efb5d207412812d2e7f5c Mon Sep 17 00:00:00 2001 From: Bruce Thelen Date: Fri, 3 Jun 2016 21:53:41 +1000 Subject: [PATCH 1/2] Add bamboo RSS feed scripts --- scripts/bamboo.check | 56 ++++++++++++++++++++++ scripts/specs/bamboo_spec.rb | 91 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100755 scripts/bamboo.check create mode 100644 scripts/specs/bamboo_spec.rb diff --git a/scripts/bamboo.check b/scripts/bamboo.check new file mode 100755 index 0000000..fe4bc6c --- /dev/null +++ b/scripts/bamboo.check @@ -0,0 +1,56 @@ +#!/usr/bin/env ruby +require 'json' +require 'open-uri' +require 'webrick' +require 'nokogiri' + +class BambooStatus + def initialize(rssUrl, rssFeed) + @rssUrl = rssUrl + @latest_build_title = rssFeed.xpath('/rss/channel/item/title').first.text + @latest_build_link = rssFeed.xpath('/rss/channel/item/link').first.text + @latest_build_description = rssFeed.xpath('/rss/channel/item/description').first + + raise ArgumentError, 'nil response from bamboo' if rssFeed.nil? + end + + def ok? + @latest_build_title.include?('was SUCCESSFUL') + end + + def as_json(*) + { + :result => ok?, + :changing => false, + :rssUrl => @rssUrl, + :info => [ + [:link, @latest_build_link], + [:title, @latest_build_title], + [:description, @latest_build_description] + ] + } + end + + def to_json(*) + JSON.dump(as_json) + end +end + +class Bamboo + def initialize(rssUrl) + raise ArgumentError 'url must not be nil' unless @rssUrl = rssUrl + end + + def latest_status + BambooStatus.new(@rssUrl, http_get_rss_feed(@rssUrl)) + end + + private + + def http_get_rss_feed(rssUrl) + rss_feed_uri = URI(WEBrick::HTTPUtils.escape(rssUrl)) + @rssFeed = Nokogiri::XML(open(rss_feed_uri)) + end +end + +puts Bamboo.new(*ARGV).latest_status.to_json if __FILE__ == $0 \ No newline at end of file diff --git a/scripts/specs/bamboo_spec.rb b/scripts/specs/bamboo_spec.rb new file mode 100644 index 0000000..ced18e1 --- /dev/null +++ b/scripts/specs/bamboo_spec.rb @@ -0,0 +1,91 @@ +$:.unshift(File.dirname(__FILE__)) +require 'spec_helper' + +describe_check :Bamboo, 'bamboo' do + bamboo_fail_xml = <<-XML + + + + Bamboo build results feed for the build + http://bamboo.local + This feed is updated whenever the build gets built + + the build has FAILED : Updated by the developer + http://bamboo.local/browse/BUILD1 + description of build + Wed, 25 May 2016 09:47:15 GMT + http://bamboo.local/browse/BUILD1 + 2016-05-25T09:47:15Z + + + the build was SUCCESSFUL : Updated by the developer + http://bamboo.local/browse/BUILD2 + description of build + Wed, 25 May 2016 09:47:15 GMT + http://bamboo.local/browse/BUILD2 + 2016-05-25T09:47:15Z + + + + XML + + bamboo_pass_xml = <<-XML + + + + Bamboo build results feed for the build + http://bamboo.local + This feed is updated whenever the build gets built + + the build was SUCCESSFUL : Updated by the developer + http://bamboo.local/browse/BUILD2 + description of build + Wed, 25 May 2016 09:47:15 GMT + http://bamboo.local/browse/BUILD2 + 2016-05-25T09:47:15Z + + + the build has FAILED : Updated by the developer + http://bamboo.local/browse/BUILD1 + description of build + Wed, 25 May 2016 09:47:15 GMT + http://bamboo.local/browse/BUILD1 + 2016-05-25T09:47:15Z + + + + XML + + before(:all) { WebMock.disable_net_connect! } + after(:all) { WebMock.allow_net_connect! } + + before(:all) do + WebMock.stub_request(:get, 'http://bamboo.local/failedbuild.rss'). + to_return(:status => 200, :body => bamboo_fail_xml, :headers => {}) + + WebMock.stub_request(:get, 'http://bamboo.local/passedbuild.rss'). + to_return(:status => 200, :body => bamboo_pass_xml, :headers => {}) + end + + context 'when the first item in the feed shows was SUCCESSFUL' do + it_returns_ok %w(http://bamboo.local/passedbuild.rss) + end + + context 'when the first item in the feed shows has FAILED' do + it_returns_fail %w(http://bamboo.local/failedbuild.rss) + end + + context 'when showing build details, provides useful links' do + let(:opts) { %w(http://bamboo.local/passedbuild.rss) } + + it 'returns an url to RSS feed' do + url = subject.latest_status.as_json[:rssUrl] + expect(url).to eq('http://bamboo.local/passedbuild.rss') + end + + it 'returns an url that links directly to the bamboo build' do + link = subject.latest_status.as_json[:info][0][1] + expect(link).to eq('http://bamboo.local/browse/BUILD2'); + end + end +end From 2e66ef129360f5a37b607cd8b6677a69b8de7603 Mon Sep 17 00:00:00 2001 From: Bruce Thelen Date: Sat, 4 Jun 2016 11:36:43 +1000 Subject: [PATCH 2/2] Added bamboo section to README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 54c6c9a..6bad36d 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,10 @@ If you ever need to kill Checkman: To get the PROJECT NAME, look at the CCTray XML and paste in the value before the ` :: ` from `` To get the STEP NAME, look at the CCTray XML and paste in the value after the ` :: ` from `` +* `bamboo.check ` + Checks your Bamboo job status using the built in RSS feeds + e.g. `bamboo.check http://bamboo.mydomain.com/rss/createAllBuildsRssFeed.action?feedType=rssAll&buildKey=MYBUILDJOB` + Above scripts are located in `/Applications/Checkman.app/Contents/Resources/`. Checkman makes these scripts available by appending stated path to PATH env variable when running check commands.