capistrano-scm-bamboo 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
4
+ *.swp
5
+ test
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capistrano-scm-bamboo.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-scm-jenkins (0.0.3)
5
+ capistrano
6
+ net-netrc
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ Platform (0.4.0)
12
+ capistrano (2.9.0)
13
+ highline
14
+ net-scp (>= 1.0.0)
15
+ net-sftp (>= 2.0.0)
16
+ net-ssh (>= 2.0.14)
17
+ net-ssh-gateway (>= 1.1.0)
18
+ diff-lcs (1.1.3)
19
+ highline (1.6.8)
20
+ net-netrc (0.2.2)
21
+ Platform (>= 0.3.0)
22
+ net-scp (1.0.4)
23
+ net-ssh (>= 1.99.1)
24
+ net-sftp (2.0.5)
25
+ net-ssh (>= 2.0.9)
26
+ net-ssh (2.2.1)
27
+ net-ssh-gateway (1.1.0)
28
+ net-ssh (>= 1.99.1)
29
+ rspec (2.7.0)
30
+ rspec-core (~> 2.7.0)
31
+ rspec-expectations (~> 2.7.0)
32
+ rspec-mocks (~> 2.7.0)
33
+ rspec-core (2.7.1)
34
+ rspec-expectations (2.7.0)
35
+ diff-lcs (~> 1.1.2)
36
+ rspec-mocks (2.7.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ capistrano-scm-jenkins!
43
+ rspec
data/NEWS.md ADDED
@@ -0,0 +1,13 @@
1
+ ## 0.0.3 (2011-12-13)
2
+
3
+ * support netrc
4
+
5
+ ## 0.0.2 (2011-11-26)
6
+
7
+ * honor :scm_username and :scm_password
8
+ * fix syntax bug under ruby 1.9
9
+
10
+
11
+ ## 0.0.1 (2011-11-25)
12
+
13
+ * initial version.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # capistrano-scm-jenkins
2
+
3
+ With this plugin, you can use jenkins build artifact as a repository, and
4
+ deploy your build artifact with capistrano.
5
+
6
+ ## INSTALL
7
+
8
+ gem install capistrano-scm-jenkins
9
+
10
+ ## USAGE
11
+
12
+ a sample config/deploy.rb
13
+
14
+ require 'capistrano-scm-jenkins'
15
+
16
+ set :application, "example"
17
+ set :repository, "http://jenkins.example.com/job/example/"
18
+
19
+ set :scm, :jenkins
20
+
21
+ # uncomment following line if you want deploy unstable version
22
+ # set :jenkins_use_unstable, true
23
+
24
+ # jenkins username and password
25
+ # set :scm_username, ENV['JENKINS_USERNAME']
26
+ # set :scm_password, ENV['JENKINS_PASSWORD']
27
+ # or use the netrc support for curl
28
+ # set :jenkins_use_netrc, true
29
+ #
30
+ # if you use netrc, add the following line in your $HOME/.netrc
31
+ # machine jenkins.example.com login USERNAME password secret
32
+
33
+
34
+ set :user, 'lidaobing'
35
+ set :use_sudo, false
36
+ set :deploy_to, "/home/#{user}/apps/#{application}"
37
+
38
+ role :web, "test.example.com" # Your HTTP server, Apache/etc
39
+ role :app, "test.example.com" # This may be the same as your `Web` server
40
+ role :db, "test.example.com", :primary => true # This is where Rails migrations will run
41
+
42
+ for more information about capistrano, check https://github.com/capistrano/capistrano
43
+
44
+ ### maven module
45
+
46
+ for the maven module, you should include the module name in your repository url. for example:
47
+
48
+ set :repository, "http://jenkins.example.com/job/example/com.example.helloworld$helloworld/"
49
+
50
+ ## LICENSE
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining
53
+ a copy of this software and associated documentation files (the
54
+ 'Software'), to deal in the Software without restriction, including
55
+ without limitation the rights to use, copy, modify, merge, publish,
56
+ distribute, sublicense, and/or sell copies of the Software, and to
57
+ permit persons to whom the Software is furnished to do so, subject to
58
+ the following conditions:
59
+
60
+ The above copyright notice and this permission notice shall be
61
+ included in all copies or substantial portions of the Software.
62
+
63
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
64
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
65
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
66
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
67
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
68
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
69
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "capistrano-scm-bamboo/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "capistrano-scm-bamboo"
7
+ s.version = Capistrano::Scm::Bamboo::VERSION
8
+ s.authors = ["John Knight"]
9
+ s.email = ["bug@knightlabs.com"]
10
+ s.homepage = "https://github.com/knightlabs/capistrano-scm-bamboo"
11
+ s.summary = %q{Use Atlassian Bamboo as a Capistrano SCM strategy}
12
+ s.description = %q{
13
+ With this plugin, you can use Bamboo build artifacts as a repository, and
14
+ deploy your build artifact with Capistrano.
15
+ }
16
+
17
+ s.rubyforge_project = "capistrano-scm-bamboo"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+
24
+ # specify any dependencies here; for example:
25
+ s.add_runtime_dependency "capistrano"
26
+ s.add_runtime_dependency "HTTParty"
27
+ s.add_development_dependency "rspec"
28
+ end
@@ -0,0 +1,186 @@
1
+ require 'HTTParty'
2
+
3
+ require 'capistrano/recipes/deploy/scm/base'
4
+
5
+ module Capistrano
6
+ module Deploy
7
+ module SCM
8
+
9
+ class Bamboo < Base
10
+ include HTTParty
11
+ base_uri repository
12
+ basic_auth scm_username, scm_passphrase
13
+
14
+ def head
15
+ last_deploy_build
16
+ end
17
+
18
+ def query_revision(revision)
19
+ return revision if revision =~ /^\d+$/
20
+ raise "invalid revision: #{revision}"
21
+ end
22
+
23
+ def checkout(revision, destination)
24
+ result = Bamboo.get('/rest/api/latest/result/CLOUD-ROUTER/18?expand=artifacts')
25
+ artifacts = result["result"]["artifacts"]["artifact"]
26
+ artifact = artifacts.select { |artifact| artifact["name"] == "router-target" }
27
+
28
+ artifactUrl = artifact[0]["link"]["href"]
29
+
30
+ %Q{TMPDIR=`mktemp -d` &&
31
+ cd "$TMPDIR" &&
32
+ wget -m -nH #{artifact_url}' &&
33
+ unzip archive.zip &&
34
+ mv archive "#{destination}" &&
35
+ rm -rf "$TMPDIR"
36
+ }
37
+ end
38
+
39
+ alias_method :export, :checkout
40
+
41
+ def log(from, to=nil)
42
+ log_build_message(from, to)
43
+ log_scm_message(from, to)
44
+ 'true'
45
+ end
46
+
47
+ def diff(from, to=nil)
48
+ logger.info 'bamboo does not support diff'
49
+ 'true'
50
+ end
51
+
52
+ private
53
+
54
+ # def authentication
55
+ # if variable(:jenkins_use_netrc)
56
+ # "--netrc"
57
+ # elsif variable(:scm_username) and variable(:scm_password)
58
+ # "--user '#{variable(:scm_username)}:#{variable(:scm_password)}'"
59
+ # else
60
+ # ""
61
+ # end
62
+ # end
63
+
64
+ # def use_unstable?
65
+ # !!variable(:jenkins_use_unstable)
66
+ # end
67
+
68
+ # def log_build_message(from, to=nil, message=nil)
69
+ # message = rss_all if message.nil?
70
+ # doc = REXML::Document.new(message).root
71
+ # logger.info ''
72
+ # logger.info "BUILD LOG"
73
+ # logger.info '========='
74
+ # REXML::XPath.each(doc,"./entry") do |entry|
75
+ # title = REXML::XPath.first(entry, "./title").text
76
+ # time = REXML::XPath.first(entry, "./updated").text
77
+ # build_number = get_build_number_from_rss_all_title(title).to_i
78
+ # if build_number > from.to_i and (to.nil? or build_number <= to.to_i)
79
+ # logger.info "#{time}\t#{title}"
80
+ # end
81
+ # end
82
+ # end
83
+
84
+ # def log_scm_message(from, to=nil, message=nil)
85
+ # message = rss_changelog if message.nil?
86
+ # doc = REXML::Document.new(message).root
87
+ # logger.info "SCM LOG"
88
+ # logger.info '======='
89
+ # REXML::XPath.each(doc,"./entry") do |entry|
90
+ # title = REXML::XPath.first(entry, "./title").text
91
+ # time = REXML::XPath.first(entry, "./updated").text
92
+ # content = REXML::XPath.first(entry, "./content").text
93
+ # build_number = get_build_number_from_rss_changelog_title(title).to_i
94
+ # if build_number > from.to_i and (to.nil? or build_number <= to.to_i)
95
+ # logger.info "#{time}\t#{title}"
96
+ # logger.info "#{content}"
97
+ # end
98
+ # end
99
+ # end
100
+
101
+ # def last_deploy_build(message = nil, opts={})
102
+ # message = rss_all if message.nil?
103
+ # use_unstable = opts[:use_unstable]
104
+ # use_unstable = use_unstable? if use_unstable.nil?
105
+ # doc = REXML::Document.new(message).root
106
+ # valid_end_strings = ['(back to normal)', '(stable)']
107
+ # if use_unstable
108
+ # valid_end_strings << '(unstable)'
109
+ # end
110
+ # REXML::XPath.each(doc,"./entry/title") do |title|
111
+ # title = title.text
112
+ # for x in valid_end_strings
113
+ # return get_build_number_from_rss_all_title(title) if title.end_with? x
114
+ # end
115
+ # end
116
+ # raise 'can not find a build suitable for deploy'
117
+ # end
118
+
119
+ # def get_build_number_from_rss_all_title(title)
120
+ # /#(\d+) \([^(]+$/.match(title)[1]
121
+ # end
122
+
123
+ # def get_build_number_from_rss_changelog_title(title)
124
+ # /^#(\d+) /.match(title)[1]
125
+ # end
126
+
127
+ # def rss_all
128
+ # begin
129
+ # @rss_all ||= open(repository + '/rssAll', auth_opts).read()
130
+ # rescue => e
131
+ # raise Capistrano::Error, "open url #{repository + '/rssAll'} failed: #{e}"
132
+ # end
133
+ # end
134
+
135
+ # def rss_changelog
136
+ # @rss_changelog ||= open(repository + '/rssChangelog', auth_opts).read()
137
+ # end
138
+
139
+ # def auth_opts
140
+ # if jenkins_username and jenkins_password
141
+ # {:http_basic_authentication => [jenkins_username, jenkins_password]}
142
+ # else
143
+ # {}
144
+ # end
145
+ # end
146
+
147
+ # def artifact_zip_url(revision)
148
+ # "#{repository}/#{revision}/artifact/*zip*/archive.zip"
149
+ # end
150
+
151
+ # def jenkins_username
152
+ # @jenkins_username ||= begin
153
+ # if variable(:jenkins_use_netrc)
154
+ # rc = Net::Netrc.locate(jenkins_hostname)
155
+ # raise ".netrc missing or no entry found" if rc.nil?
156
+ # rc.login
157
+ # elsif variable(:scm_username)
158
+ # variable(:scm_username)
159
+ # else
160
+ # nil
161
+ # end
162
+ # end
163
+ # end
164
+
165
+ # def jenkins_password
166
+ # @jenkins_password ||= begin
167
+ # if variable(:jenkins_use_netrc)
168
+ # rc = Net::Netrc.locate(jenkins_hostname)
169
+ # raise ".netrc missing or no entry found" if rc.nil?
170
+ # rc.password
171
+ # elsif variable(:scm_password)
172
+ # variable(:scm_password)
173
+ # else
174
+ # nil
175
+ # end
176
+ # end
177
+ # end
178
+
179
+ # def jenkins_hostname
180
+ # @jenkins_hostname ||= URI.parse(repository).host
181
+ # end
182
+
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,7 @@
1
+ module Capistrano
2
+ module Scm
3
+ module Bamboo
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ require "capistrano-scm-bamboo/version"
2
+ require "capistrano/recipes/deploy/scm/bamboo"
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'capistrano/recipes/deploy/scm/bamboo'
3
+
4
+ module Capistrano::Deploy::SCM
5
+ describe Bamboo do
6
+ before :each do
7
+ @bamboo = Bamboo.new
8
+ end
9
+
10
+ context "last_deploy_build" do
11
+ it "should support back to normal" do
12
+ msg = %Q{<?xml version="1.0" encoding="UTF-8"?>
13
+ <feed xmlns="http://www.w3.org/2005/Atom"><title>estore-nginx all builds</title><link type="text/html" href="http://ci.eb.in.sdo.com/view/eStore/job/estore-nginx/" rel="alternate"/><updated>2011-11-24T07:11:06Z</updated><author><name>Jenkins Server</name></author><id>urn:uuid:903deee0-7bfa-11db-9fe1-0800200c9a66</id><entry><title>estore-nginx #2 (back to normal)</title><link type="text/html" href="http://ci.eb.in.sdo.com/view/eStore/job/estore-nginx/2/" rel="alternate"/><id>tag:hudson.dev.java.net,2011:estore-nginx:2011-11-24_15-11-06</id><published>2011-11-24T07:11:06Z</published><updated>2011-11-24T07:11:06Z</updated></entry><entry><title>estore-nginx #1 (broken for a long time)</title><link type="text/html" href="http://ci.eb.in.sdo.com/view/eStore/job/estore-nginx/1/" rel="alternate"/><id>tag:hudson.dev.java.net,2011:estore-nginx:2011-11-24_15-09-18</id><published>2011-11-24T07:09:18Z</published><updated>2011-11-24T07:09:18Z</updated></entry></feed>}
14
+ @jenkins.send(:last_deploy_build, msg).should == '2'
15
+ end
16
+
17
+ it "should support stable" do
18
+ msg = %Q{<?xml version="1.0" encoding="UTF-8"?>
19
+ <feed xmlns="http://www.w3.org/2005/Atom"><title>cerl all builds</title><link type="text/html" href="http://ci.eb.in.sdo.com/view/eStore/job/cerl/" rel="alternate"/><updated>2011-11-17T05:17:58Z</updated><author><name>Jenkins Server</name></author><id>urn:uuid:903deee0-7bfa-11db-9fe1-0800200c9a66</id><entry><title>cerl #98 (stable)</title><link type="text/html" href="http://ci.eb.in.sdo.com/view/eStore/job/cerl/98/" rel="alternate"/><id>tag:hudson.dev.java.net,2011:cerl:2011-11-17_13-17-58</id><published>2011-11-17T05:17:58Z</published><updated>2011-11-17T05:17:58Z</updated></entry><entry><title>cerl #97 (stable)</title><link type="text/html" href="http://ci.eb.in.sdo.com/view/eStore/job/cerl/97/" rel="alternate"/><id>tag:hudson.dev.java.net,2011:cerl:2011-11-12_18-27-58</id><published>2011-11-12T10:27:58Z</published><updated>2011-11-12T10:27:58Z</updated></entry></feed>}
20
+ @jenkins.send(:last_deploy_build, msg).should == '98'
21
+ end
22
+
23
+ it "should honor unstable" do
24
+ msg = %Q{<?xml version="1.0" encoding="UTF-8"?>
25
+ <feed xmlns="http://www.w3.org/2005/Atom"><title>IndexCoordinator all builds</title><link type="text/html" href="http://ci.eb.in.sdo.com/job/IndexCoordinator/" rel="alternate"/><updated>2011-11-24T09:22:32Z</updated><author><name>Jenkins Server</name></author><id>urn:uuid:903deee0-7bfa-11db-9fe1-0800200c9a66</id><entry><title>IndexCoordinator #1450 (unstable)</title><link type="text/html" href="http://ci.eb.in.sdo.com/job/IndexCoordinator/1450/" rel="alternate"/><id>tag:hudson.dev.java.net,2011:IndexCoordinator:2011-11-22_19-44-23</id><published>2011-11-22T11:44:23Z</published><updated>2011-11-22T11:44:23Z</updated></entry><entry><title>IndexCoordinator #1449 (back to normal)</title><link type="text/html" href="http://ci.eb.in.sdo.com/job/IndexCoordinator/1449/" rel="alternate"/><id>tag:hudson.dev.java.net,2011:IndexCoordinator:2011-11-22_19-23-22</id><published>2011-11-22T11:23:22Z</published><updated>2011-11-22T11:23:22Z</updated></entry><entry><title>IndexCoordinator #1448 (broken since this build)</title><link type="text/html" href="http://ci.eb.in.sdo.com/job/IndexCoordinator/1448/" rel="alternate"/><id>tag:hudson.dev.java.net,2011:IndexCoordinator:2011-11-22_19-10-50</id><published>2011-11-22T11:10:50Z</published><updated>2011-11-22T11:10:50Z</updated></entry></feed>
26
+ }
27
+ @jenkins.send(:last_deploy_build, msg).should == '1449'
28
+ @jenkins.send(:last_deploy_build, msg, :use_unstable => true).should == '1450'
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1 @@
1
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-scm-bamboo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Knight
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: &70355809457960 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70355809457960
25
+ - !ruby/object:Gem::Dependency
26
+ name: HTTParty
27
+ requirement: &70355809380760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70355809380760
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70355809237160 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70355809237160
47
+ description: ! "\nWith this plugin, you can use Bamboo build artifacts as a repository,
48
+ and\ndeploy your build artifact with Capistrano.\n "
49
+ email:
50
+ - bug@knightlabs.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .rspec
57
+ - Gemfile
58
+ - Gemfile.lock
59
+ - NEWS.md
60
+ - README.md
61
+ - Rakefile
62
+ - capistrano-scm-bamboo.gemspec
63
+ - lib/capistrano-scm-bamboo.rb
64
+ - lib/capistrano-scm-bamboo/version.rb
65
+ - lib/capistrano/recipes/deploy/scm/bamboo.rb
66
+ - spec/capistrano/recipes/deploy/scm/bamboo_spec.rb
67
+ - spec/spec_helper.rb
68
+ homepage: https://github.com/knightlabs/capistrano-scm-bamboo
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project: capistrano-scm-bamboo
88
+ rubygems_version: 1.8.11
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Use Atlassian Bamboo as a Capistrano SCM strategy
92
+ test_files:
93
+ - spec/capistrano/recipes/deploy/scm/bamboo_spec.rb
94
+ - spec/spec_helper.rb