chef-handler-jenkins 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -0
- data/LICENSE +21 -0
- data/README.md +28 -0
- data/chef-handler-jenkins.gemspec +15 -0
- data/lib/chef/handler/jenkins.rb +93 -0
- metadata +83 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014, Jenkins project
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
This is a Chef report handler that allows [Jenkins](http://jenkins-ci.org/) to track
|
2
|
+
when files are deployed where.
|
3
|
+
|
4
|
+
# Usage
|
5
|
+
There are two ways to configure Chef Handler.
|
6
|
+
|
7
|
+
## Via solo.rb or client.rb
|
8
|
+
Install `chef-handler-jenkins` gem upfront first:
|
9
|
+
|
10
|
+
$ gem install chef-handler-jenkins
|
11
|
+
|
12
|
+
Then configure Chef to use it with the following lines. For chef-solo, you can put that in your [/etc/chef/solo.rb](http://docs.opscode.com/config_rb_solo.html) (or your local override). For chef-client, you can put that in your [/etc/chef/client.rb](http://docs.opscode.com/config_rb_client.html).
|
13
|
+
|
14
|
+
require 'chef/handler/jenkins'
|
15
|
+
report_handlers << Chef::Handler::Jenkins.new(:url => 'http://myserver.acme.com/jenkins')
|
16
|
+
|
17
|
+
This approach is best suited if you own the operation environment and want to do the deployment integration without modifying recipes.
|
18
|
+
|
19
|
+
## Via recipes
|
20
|
+
Use [chef_handler cookbook](http://community.opscode.com/cookbooks/chef_handler) and activate this handler via your recipe:
|
21
|
+
|
22
|
+
chef_gem 'chef-handler-jenkins'
|
23
|
+
|
24
|
+
chef_handler 'Chef::Handler::Jenkins' do
|
25
|
+
source 'chef/handler/jenkins'
|
26
|
+
arguments :url => 'http://myserver.acme.com/jenkins'
|
27
|
+
action :enable
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |g|
|
2
|
+
g.name = 'chef-handler-jenkins'
|
3
|
+
g.version = '0.1'
|
4
|
+
|
5
|
+
g.summary = 'Chef report handler for tracking with Jenkins'
|
6
|
+
g.description = 'Track deployment of files through Jenkins'
|
7
|
+
g.authors = ['Kohsuke Kawaguchi']
|
8
|
+
g.email = 'kk@kohsuke.org'
|
9
|
+
g.homepage = 'http://jenkins-ci.org/'
|
10
|
+
|
11
|
+
g.require_paths = ['lib']
|
12
|
+
g.files = `git ls-files`.split($\)
|
13
|
+
|
14
|
+
g.add_dependency 'chef', '>=11.6'
|
15
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "chef/log"
|
2
|
+
require 'digest/md5'
|
3
|
+
|
4
|
+
module Chef
|
5
|
+
module Handler
|
6
|
+
#noinspection RubyStringKeysInHashInspection
|
7
|
+
class TrackingHandler < Chef::Handler
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
raise ArgumentError, 'Jenkins URL is not specified' unless @config[:url]
|
11
|
+
end
|
12
|
+
|
13
|
+
def report
|
14
|
+
# for interactive exploration
|
15
|
+
#require 'pry'
|
16
|
+
#binding.pry
|
17
|
+
|
18
|
+
updates = []
|
19
|
+
|
20
|
+
puts "Machine name: #{run_status.node.name}"
|
21
|
+
run_status.updated_resources.each do |res|
|
22
|
+
# res is instance of CookbookFile
|
23
|
+
if res.class <= Chef::Resource::File
|
24
|
+
updates << {
|
25
|
+
"path" => res.path,
|
26
|
+
"action" => res.action,
|
27
|
+
"md5" => Digest::MD5.hexdigest(IO.read(res.path)),
|
28
|
+
"type" => res.class.name
|
29
|
+
}
|
30
|
+
# res.checksum is SHA1 sum
|
31
|
+
end
|
32
|
+
|
33
|
+
if res.class == Chef::Resource::SaladJenkinsTracking
|
34
|
+
# TODO is this a good way to check the class name?
|
35
|
+
updates << {
|
36
|
+
"path" => res.path,
|
37
|
+
"md5" => res.checksum,
|
38
|
+
"type" => res.class.name
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# add envelop to the data
|
44
|
+
env = {
|
45
|
+
"node" => run_status.node.name,
|
46
|
+
"environment" => run_status.node.environment,
|
47
|
+
"start_time" => run_status.start_time.rfc2822,
|
48
|
+
"end_time" => run_status.end_time.rfc2822,
|
49
|
+
"updates" => updates
|
50
|
+
}
|
51
|
+
|
52
|
+
print env.inspect
|
53
|
+
|
54
|
+
if false # TODO: work in progress
|
55
|
+
# if !Chef::Config[:solo]
|
56
|
+
# databag submission only works in chef-client
|
57
|
+
submit_databag run_status,env
|
58
|
+
end
|
59
|
+
submit_jenkins run_status,env
|
60
|
+
end
|
61
|
+
|
62
|
+
# Submit the tracking report as a databag
|
63
|
+
#
|
64
|
+
# @param [Chef::RunStatus] run_status
|
65
|
+
# @param [Hash] report
|
66
|
+
def submit_databag(run_status, env)
|
67
|
+
# TODO: too expensive to load them. all we want to do is to check if databag exists
|
68
|
+
#begin
|
69
|
+
# Chef::DataBag.load("jenkins")
|
70
|
+
#rescue Net::HTTPServerException => e
|
71
|
+
# if e.response.code=="404"
|
72
|
+
# bag = Chef::DataBag.new
|
73
|
+
# bag.name "jenkins"
|
74
|
+
# bag.save
|
75
|
+
# end
|
76
|
+
#end
|
77
|
+
|
78
|
+
i = Chef::DataBagItem.new
|
79
|
+
i.data_bag("jenkins") # set the name
|
80
|
+
|
81
|
+
id = run_status.node.name + '_' + run_status.end_time.strftime("%Y%m%d-%H%M%S")
|
82
|
+
|
83
|
+
i.raw_data = env
|
84
|
+
i.save id
|
85
|
+
end
|
86
|
+
|
87
|
+
def submit_jenkins(run_status, env)
|
88
|
+
r = Chef::REST.new(@config[:url])
|
89
|
+
r.post("chef/report", env)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-handler-jenkins
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kohsuke Kawaguchi
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2014-03-31 00:00:00 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: chef
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 43
|
28
|
+
segments:
|
29
|
+
- 11
|
30
|
+
- 6
|
31
|
+
version: "11.6"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Track deployment of files through Jenkins
|
35
|
+
email: kk@kohsuke.org
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- Gemfile
|
44
|
+
- LICENSE
|
45
|
+
- README.md
|
46
|
+
- chef-handler-jenkins.gemspec
|
47
|
+
- lib/chef/handler/jenkins.rb
|
48
|
+
homepage: http://jenkins-ci.org/
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.15
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Chef report handler for tracking with Jenkins
|
81
|
+
test_files: []
|
82
|
+
|
83
|
+
has_rdoc:
|