jenkins-capistrano 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +53 -0
- data/Rakefile +2 -0
- data/jenkins-capistrano.gemspec +23 -0
- data/lib/jenkins-capistrano.rb +55 -0
- data/lib/jenkins-capistrano/client.rb +53 -0
- data/lib/jenkins-capistrano/version.rb +5 -0
- metadata +124 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 cynipe
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# jenkins-capistrano
|
2
|
+
|
3
|
+
The capistrano tasks for Jenkins CI Server
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'jenkins-capistrano'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install jenkins-capistrano
|
18
|
+
|
19
|
+
## Example
|
20
|
+
|
21
|
+
The following code will creates or updates Jenkins jobs before each deploy task:
|
22
|
+
|
23
|
+
config directory structure(name your config.xml as a job name):
|
24
|
+
|
25
|
+
config
|
26
|
+
├── deploy.rb
|
27
|
+
└── jenkins
|
28
|
+
└── jobs
|
29
|
+
├── job-name1.xml
|
30
|
+
├── job-name2.xml
|
31
|
+
└── job-name3.xml
|
32
|
+
|
33
|
+
|
34
|
+
deploy.rb:
|
35
|
+
|
36
|
+
set :application, "your-awesome-app"
|
37
|
+
set :scm, :git
|
38
|
+
set :repository, "https://github.com/your/repository.git"
|
39
|
+
|
40
|
+
set :jenkins_host, 'http://localhost:8080'
|
41
|
+
# set :jenkins_username, '' # default empty
|
42
|
+
# set :jenkins_password, '' # default empty
|
43
|
+
# set :jenkins_job_config_dir, 'config/jenkins/jobs'
|
44
|
+
|
45
|
+
before 'deploy', 'jenkins:deploy_jobs'
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/jenkins-capistrano/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["cynipe"]
|
6
|
+
gem.email = ["cynipe@gmail.com"]
|
7
|
+
gem.description = %q{The capistrano tasks for Jenkins CI Server}
|
8
|
+
gem.summary = %q{}
|
9
|
+
gem.homepage = "https://github.com/cynipe/jenkins-capistrano"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "jenkins-capistrano"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Jenkins::Capistrano::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'capistrano'
|
19
|
+
gem.add_dependency 'httparty', '~> 0.6.1'
|
20
|
+
gem.add_dependency 'hpricot'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'jenkins-capistrano/version'
|
2
|
+
require 'jenkins-capistrano/client'
|
3
|
+
|
4
|
+
def _cset(name, *args, &block)
|
5
|
+
unless exists?(name)
|
6
|
+
set(name, *args, &block)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Capistrano task for Jenkins.
|
11
|
+
#
|
12
|
+
# Just add "require 'jenkins-capistrano'" in your Capistrano deploy.rb, and
|
13
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
14
|
+
|
15
|
+
_cset(:jenkins_host) { abort "Please specify the host of your jenkins server, set :jenkins_host, 'http://localhost:8080'" }
|
16
|
+
|
17
|
+
_cset(:jenkins_username) { '' }
|
18
|
+
_cset(:jenkins_password) { '' }
|
19
|
+
|
20
|
+
_cset(:jenkins_job_config_dir) { 'config/jenkins/jobs' }
|
21
|
+
|
22
|
+
def client
|
23
|
+
@client ||= Jenkins::Client.new(jenkins_host, { :username => jenkins_username, :password => jenkins_password})
|
24
|
+
end
|
25
|
+
|
26
|
+
def job_configs
|
27
|
+
Dir.glob("#{jenkins_job_config_dir}/*.xml")
|
28
|
+
end
|
29
|
+
|
30
|
+
# minimum configurations
|
31
|
+
#
|
32
|
+
# role :jenkins, 'localhost:8080'
|
33
|
+
namespace :jenkins do
|
34
|
+
|
35
|
+
desc <<-DESC
|
36
|
+
Deploy the jobs to Jenkins server -- meaning create or update --
|
37
|
+
|
38
|
+
set :jenkins_job_config_dir, 'config/jenkins/jobs'
|
39
|
+
set :jenkins_job_deploy_strategy, :clean | :merge
|
40
|
+
DESC
|
41
|
+
task :deploy_jobs do
|
42
|
+
strategy = fetch(:jenkins_job_deploy_strategy, :clean)
|
43
|
+
logger.info "deploying jenkins jobs to #{jenkins_host}"
|
44
|
+
logger.warn "no job configs found." if job_configs.empty?
|
45
|
+
job_configs.each do |file|
|
46
|
+
name = File.basename(file, '.xml')
|
47
|
+
client.create_or_update_job(name, File.read(file))
|
48
|
+
logger.trace "job #{name} created."
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'cgi/util'
|
3
|
+
|
4
|
+
module Jenkins
|
5
|
+
class Client
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
headers 'content-type' => 'application/json'
|
9
|
+
format :json
|
10
|
+
|
11
|
+
ServerError = Class.new(Exception)
|
12
|
+
|
13
|
+
def initialize(host, opts = {})
|
14
|
+
self.class.base_uri host
|
15
|
+
@auth = { :username => opts[:username], :password => opts[:password] }
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_job(name, config)
|
19
|
+
res = self.class.post("/createItem/api/xml?name=#{CGI.escape(name)}", xml_body(config))
|
20
|
+
raise ServerError, parse_error_message(res) unless res.code.to_i == 200
|
21
|
+
end
|
22
|
+
|
23
|
+
def update_job(name, config)
|
24
|
+
res = self.class.post("/job/#{CGI.escape(name)}/config.xml", xml_body(config))
|
25
|
+
raise ServerError, parse_error_message(res) unless res.code.to_i == 200
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_or_update_job(name, config)
|
29
|
+
begin
|
30
|
+
create_job(name, config)
|
31
|
+
rescue ServerError => e
|
32
|
+
update_job(name, config)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def xml_body(xml_str)
|
38
|
+
{
|
39
|
+
:body => xml_str,
|
40
|
+
:format => :xml,
|
41
|
+
:headers => { 'content-type' => 'application/xml' }
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse_error_message(response)
|
46
|
+
require "hpricot"
|
47
|
+
doc = Hpricot(response.body)
|
48
|
+
error_msg = doc.search("td#main-panel p")
|
49
|
+
error_msg.inner_text.empty? ? "Server error: code=#{response.code}, #{response.body}" : error_msg
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jenkins-capistrano
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- cynipe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: httparty
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.6.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.6.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: hpricot
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: The capistrano tasks for Jenkins CI Server
|
79
|
+
email:
|
80
|
+
- cynipe@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- jenkins-capistrano.gemspec
|
91
|
+
- lib/jenkins-capistrano.rb
|
92
|
+
- lib/jenkins-capistrano/client.rb
|
93
|
+
- lib/jenkins-capistrano/version.rb
|
94
|
+
homepage: https://github.com/cynipe/jenkins-capistrano
|
95
|
+
licenses: []
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
hash: 1302073719189149313
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
hash: 1302073719189149313
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.8.24
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: ''
|
124
|
+
test_files: []
|