Created
January 10, 2013 23:41
-
-
Save zeha/4506759 to your computer and use it in GitHub Desktop.
git post-receive hook for triggering Jenkins builds. Jenkins must be set up to poll the SCM, but the schedule can be empty.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# git config --add hooks.jenkins.giturl <git url you've configured in jenkins> | |
# git config --add hooks.jenkins.jenkinsurl https://your.jenkins.host/ | |
require 'rubygems' | |
require "net/http" | |
require "uri" | |
repopath = File.expand_path(__FILE__ + '/../../').split('/') | |
repopath.shift 4 | |
reponame = repopath.join('/').gsub('.git','') | |
git_url = `git config hooks.jenkins.giturl 2>/dev/null`.strip | |
jenkins_url = `git config hooks.jenkins.jenkinsurl 2>/dev/null`.strip | |
if git_url.empty? or jenkins_url.empty? then | |
exit 0 | |
end | |
url = "#{jenkins_url}/git/notifyCommit?url=#{git_url}" | |
uri = URI.parse(url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
if uri.scheme == "https" then | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
end | |
request = Net::HTTP::Get.new(uri.request_uri) | |
response = http.request(request) | |
puts "jenkins: #{response.body}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment