capistrano-scm-jenkins 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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-jenkins.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-scm-jenkins (0.0.1)
5
+ capistrano
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ capistrano (2.9.0)
11
+ highline
12
+ net-scp (>= 1.0.0)
13
+ net-sftp (>= 2.0.0)
14
+ net-ssh (>= 2.0.14)
15
+ net-ssh-gateway (>= 1.1.0)
16
+ diff-lcs (1.1.2)
17
+ highline (1.6.2)
18
+ net-scp (1.0.4)
19
+ net-ssh (>= 1.99.1)
20
+ net-sftp (2.0.5)
21
+ net-ssh (>= 2.0.9)
22
+ net-ssh (2.1.4)
23
+ net-ssh-gateway (1.1.0)
24
+ net-ssh (>= 1.99.1)
25
+ rspec (2.7.0)
26
+ rspec-core (~> 2.7.0)
27
+ rspec-expectations (~> 2.7.0)
28
+ rspec-mocks (~> 2.7.0)
29
+ rspec-core (2.7.1)
30
+ rspec-expectations (2.7.0)
31
+ diff-lcs (~> 1.1.2)
32
+ rspec-mocks (2.7.0)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ capistrano-scm-jenkins!
39
+ rspec
data/README.md ADDED
@@ -0,0 +1,62 @@
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
+ # uncomment following line if you want deploy unstable version
21
+ # set :jenkins_use_unstable, true
22
+ set :user, 'lidaobing'
23
+ set :use_sudo, false
24
+ set :deploy_to, "/home/#{user}/apps/#{application}"
25
+
26
+ role :web, "test.example.com" # Your HTTP server, Apache/etc
27
+ role :app, "test.example.com" # This may be the same as your `Web` server
28
+ role :db, "test.example.com", :primary => true # This is where Rails migrations will run
29
+
30
+ for more information about capistrano, check https://github.com/capistrano/capistrano
31
+
32
+ ### maven module
33
+
34
+ for the maven module, you should include the module name in your repository url. for example:
35
+
36
+ set :repository, "http://jenkins.example.com/job/example/com.example.helloworld$helloworld/"
37
+
38
+ ## TODO
39
+
40
+ * how to deal with auth? (need help)
41
+ * support unstable build
42
+
43
+ ## LICENSE
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining
46
+ a copy of this software and associated documentation files (the
47
+ 'Software'), to deal in the Software without restriction, including
48
+ without limitation the rights to use, copy, modify, merge, publish,
49
+ distribute, sublicense, and/or sell copies of the Software, and to
50
+ permit persons to whom the Software is furnished to do so, subject to
51
+ the following conditions:
52
+
53
+ The above copyright notice and this permission notice shall be
54
+ included in all copies or substantial portions of the Software.
55
+
56
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
57
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
58
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
59
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
60
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
61
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
62
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "capistrano-scm-jenkins/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "capistrano-scm-jenkins"
7
+ s.version = Capistrano::Scm::Jenkins::VERSION
8
+ s.authors = ["LI Daobing"]
9
+ s.email = ["lidaobing@gmail.com"]
10
+ s.homepage = "https://github.com/lidaobing/capistrano-scm-jenkins"
11
+ s.summary = %q{use jenkins as a capistrano scm}
12
+ s.description = %q{use jenkins as a capistrano scm}
13
+
14
+ s.rubyforge_project = "capistrano-scm-jenkins"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_runtime_dependency "capistrano"
23
+ s.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,2 @@
1
+ require "capistrano-scm-jenkins/version"
2
+ require "capistrano/recipes/deploy/scm/jenkins"
@@ -0,0 +1,7 @@
1
+ module Capistrano
2
+ module Scm
3
+ module Jenkins
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,122 @@
1
+ require 'open-uri'
2
+ require 'tmpdir'
3
+ require 'rexml/document'
4
+
5
+ require 'capistrano/recipes/deploy/scm/base'
6
+
7
+ module Capistrano
8
+ module Deploy
9
+ module SCM
10
+ class Jenkins < Base
11
+ def head
12
+ last_deploy_build
13
+ end
14
+
15
+ def query_revision(revision)
16
+ return revision if revision =~ /^\d+$/
17
+ raise "invalid revision: #{revision}"
18
+ end
19
+
20
+ def checkout(revision, destination)
21
+ %Q{TMPDIR=`mktemp -d` &&
22
+ cd "$TMPDIR" &&
23
+ wget -nv '#{artifact_zip_url(revision)}' &&
24
+ unzip archive.zip &&
25
+ mv archive "#{destination}" &&
26
+ rm -rf "$TMPDIR"
27
+ }
28
+ end
29
+
30
+ alias_method :export, :checkout
31
+
32
+ def log(from, to=nil)
33
+ log_build_message(from, to)
34
+ log_scm_message(from, to)
35
+ 'true'
36
+ end
37
+
38
+ def diff(from, to=nil)
39
+ logger.info 'jenkins does not support diff'
40
+ 'true'
41
+ end
42
+
43
+ private
44
+
45
+ def use_unstable?
46
+ !!variable(:jenkins_use_unstable)
47
+ end
48
+
49
+ def log_build_message(from, to=nil, message=nil)
50
+ message = rss_all if message.nil?
51
+ doc = REXML::Document.new(message).root
52
+ logger.info ''
53
+ logger.info "BUILD LOG"
54
+ logger.info '========='
55
+ REXML::XPath.each(doc,"./entry") do |entry|
56
+ title = REXML::XPath.first(entry, "./title").text
57
+ time = REXML::XPath.first(entry, "./updated").text
58
+ build_number = get_build_number_from_rss_all_title(title).to_i
59
+ if build_number > from.to_i and (to.nil? or build_number <= to.to_i)
60
+ logger.info "#{time}\t#{title}"
61
+ end
62
+ end
63
+ end
64
+
65
+ def log_scm_message(from, to=nil, message=nil)
66
+ message = rss_changelog if message.nil?
67
+ doc = REXML::Document.new(message).root
68
+ logger.info "SCM LOG"
69
+ logger.info '======='
70
+ REXML::XPath.each(doc,"./entry") do |entry|
71
+ title = REXML::XPath.first(entry, "./title").text
72
+ time = REXML::XPath.first(entry, "./updated").text
73
+ content = REXML::XPath.first(entry, "./content").text
74
+ build_number = get_build_number_from_rss_changelog_title(title).to_i
75
+ if build_number > from.to_i and (to.nil? or build_number <= to.to_i)
76
+ logger.info "#{time}\t#{title}"
77
+ logger.info "#{content}"
78
+ end
79
+ end
80
+ end
81
+
82
+ def last_deploy_build(message = nil, opts={})
83
+ message = rss_all if message.nil?
84
+ use_unstable = opts[:use_unstable]
85
+ use_unstable = use_unstable? if use_unstable.nil?
86
+ doc = REXML::Document.new(message).root
87
+ valid_end_strings = ['(back to normal)', '(stable)']
88
+ if use_unstable
89
+ valid_end_strings << '(unstable)'
90
+ end
91
+ REXML::XPath.each(doc,"./entry/title") do |title|
92
+ title = title.text
93
+ for x in valid_end_strings:
94
+ return get_build_number_from_rss_all_title(title) if title.end_with? x
95
+ end
96
+ end
97
+ raise 'can not find a build suitable for deploy'
98
+ end
99
+
100
+ def get_build_number_from_rss_all_title(title)
101
+ /#(\d+) \([^(]+$/.match(title)[1]
102
+ end
103
+
104
+ def get_build_number_from_rss_changelog_title(title)
105
+ /^#(\d+) /.match(title)[1]
106
+ end
107
+
108
+ def rss_all
109
+ @rss_all ||= open(repository + '/rssAll').read()
110
+ end
111
+
112
+ def rss_changelog
113
+ @rss_changelog ||= open(repository + '/rssChangelog').read()
114
+ end
115
+
116
+ def artifact_zip_url(revision)
117
+ "#{repository}/#{revision}/artifact/*zip*/archive.zip"
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'capistrano/recipes/deploy/scm/jenkins'
3
+
4
+ module Capistrano::Deploy::SCM
5
+ describe Jenkins do
6
+ before :each do
7
+ @jenkins = Jenkins.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,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-scm-jenkins
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - LI Daobing
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-25 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: capistrano
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: use jenkins as a capistrano scm
50
+ email:
51
+ - lidaobing@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - .rspec
61
+ - Gemfile
62
+ - Gemfile.lock
63
+ - README.md
64
+ - Rakefile
65
+ - capistrano-scm-jenkins.gemspec
66
+ - lib/capistrano-scm-jenkins.rb
67
+ - lib/capistrano-scm-jenkins/version.rb
68
+ - lib/capistrano/recipes/deploy/scm/jenkins.rb
69
+ - spec/capistrano/recipes/deploy/scm/jenkins_spec.rb
70
+ - spec/spec_helper.rb
71
+ has_rdoc: true
72
+ homepage: https://github.com/lidaobing/capistrano-scm-jenkins
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project: capistrano-scm-jenkins
101
+ rubygems_version: 1.6.2
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: use jenkins as a capistrano scm
105
+ test_files: []
106
+