chef-handler-jenkins_notifier 0.0.3

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b599050804af5bebd29b572bd7573eb792f90d6
4
+ data.tar.gz: bf1e0d85d5269f1627d594050b3860ef8d9c01b8
5
+ SHA512:
6
+ metadata.gz: 2e418d48ed82d8697bfb8bcb5cc9696cc26e1feb9446073ccacd6d6b36c5a0260dbcaabc27f5e59af4d33c7a6285c42be39fc2bde445bdeb49f56f54581887ac
7
+ data.tar.gz: 82d94d0877ac90bcd44b51dda3922444b2892b42ddcfc187a299f758966b9e76e9e322de12d171057eae131a03a12b2c8b4b193af5c2a30a310d8b5418a195cc
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chef-handler-jenkins_notifier.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
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,76 @@
1
+ # Chef::Handler::JenkinsNotifier
2
+
3
+ The chef-handler-jenkins_notifier gem is a Chef report mechanism that sends
4
+ failures to a Jenkins Job.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'chef-handler-jenkins_notifier'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install chef-handler-jenkins_notifier
19
+
20
+ ## Usage
21
+
22
+ ### Create Jenkins Job
23
+
24
+ Create a Jenkins job.
25
+
26
+ ### Create recipe
27
+
28
+ Create a new recipe, with the following contents, and add it to the runlist of your base role in Chef:
29
+
30
+ ```ruby
31
+ chef_gem "chef-handler-jenkins_notifier" do
32
+ action :upgrade
33
+ end
34
+
35
+ require 'chef/handler/jenkins_notifier'
36
+
37
+ chef_handler 'Chef::Handler::Jenkins_Notifier' do
38
+ source 'chef/handler/jenkins_notifier'
39
+ arguments [
40
+ :host => "#{JENKINS_HOST}",
41
+ :port => "#{JENKINS_PORT}",
42
+ :path => "/job/#{JOB_NAME}/postBuildResult"
43
+ ]
44
+ action :nothing
45
+ end.run_action(:enable)
46
+ ```
47
+
48
+ Recipe is written as follows: If you use authentication in Jenkins.
49
+
50
+ ```ruby
51
+ chef_gem "chef-handler-jenkins_notifier" do
52
+ action :upgrade
53
+ end
54
+
55
+ require 'chef/handler/jenkins_notifier'
56
+
57
+ chef_handler 'Chef::Handler::Jenkins_Notifier' do
58
+ source 'chef/handler/jenkins_notifier'
59
+ arguments [
60
+ :host => "#{JENKINS_HOST}",
61
+ :port => "#{JENKINS_PORT}",
62
+ :path => "/job/#{JOB_NAME}/postBuildResult",
63
+ :user => "#{user}",
64
+ :pass => "#{pass}"
65
+ ]
66
+ action :nothing
67
+ end.run_action(:enable)
68
+ ```
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it ( https://github.com/[my-github-username]/chef-handler-jenkins_notifier/fork )
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ require "bundler/gem_helper"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chef/handler/jenkins_notifier/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chef-handler-jenkins_notifier"
8
+ spec.version = Chef::Handler::JenkinsNotifier::VERSION
9
+ spec.authors = ["Yohei Kawahara(inokappa)"]
10
+ spec.email = ["inokara@gmail.com"]
11
+ spec.summary = %q{Chef notification handler for Jenkins}
12
+ spec.description = %q{Chef notification handler for Jenkins}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,56 @@
1
+ require "chef/handler/jenkins_notifier/version"
2
+ require "chef/log"
3
+ require "net/http"
4
+ require 'digest/md5'
5
+
6
+ class Chef
7
+ class Handler
8
+ #noinspection RubyStringKeysInHashInspection
9
+ class Jenkins_Notifier < Chef::Handler
10
+ def initialize(config)
11
+ @config = config
12
+ raise ArgumentError, 'Jenkins Host is not specified' unless @config[:host]
13
+ raise ArgumentError, 'Jenkins Port is not specified' unless @config[:port]
14
+ raise ArgumentError, 'Jenkins Job Path is not specified' unless @config[:path]
15
+ end
16
+
17
+ def report
18
+ log = []
19
+ if not run_status.success?
20
+ result = 1
21
+ log << "\n"
22
+ log << "Chef run failed on #{run_status.node.name}"
23
+ if !run_status.exception.nil?
24
+ log << run_status.formatted_exception.encode('UTF-8', {:invalid => :replace, :undef => :replace, :replace => '?'})
25
+ end
26
+ log << "\n"
27
+ log = log.join("\n")
28
+ submit_jenkins run_status,log,result
29
+ else
30
+ result = 0
31
+ log << "\n"
32
+ log << "Chef run Success on #{run_status.node.name}"
33
+ log << "environment: " + run_status.node.environment
34
+ log << "start_time: " + run_status.start_time.rfc2822
35
+ log << "end_time: " + run_status.end_time.rfc2822
36
+ log << "elapsed_time: " + run_status.elapsed_time.to_s + "s"
37
+ log << "\n"
38
+ log = log.join("\n")
39
+ submit_jenkins run_status,log,result
40
+ end
41
+ end
42
+
43
+ def submit_jenkins(run_status, log, result)
44
+ binlog = log.unpack("H*").first
45
+ ms = (run_status.elapsed_time * 1000).round
46
+ data = "<run><log encoding='hexBinary'>#{binlog}</log><result>#{result}</result><duration>#{ms}</duration></run>"
47
+ req = Net::HTTP::Post.new(@config[:path])
48
+ if @config[:user] && @config[:pass]
49
+ req.basic_auth @config[:user], @config[:pass]
50
+ end
51
+ req.set_body_internal(data)
52
+ res = Net::HTTP.new(@config[:host],@config[:port]).start {|http| http.request(req)}
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ class Chef
2
+ class Handler
3
+ module JenkinsNotifier
4
+ VERSION = "0.0.3"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-handler-jenkins_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Yohei Kawahara(inokappa)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Chef notification handler for Jenkins
42
+ email:
43
+ - inokara@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - chef-handler-jenkins_notifier.gemspec
54
+ - lib/chef/handler/jenkins_notifier.rb
55
+ - lib/chef/handler/jenkins_notifier/version.rb
56
+ homepage: ''
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.0.14
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Chef notification handler for Jenkins
80
+ test_files: []