Skip to content

Instantly share code, notes, and snippets.

@techpeace
Created October 27, 2010 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techpeace/649998 to your computer and use it in GitHub Desktop.
Save techpeace/649998 to your computer and use it in GitHub Desktop.
Polls your git repo and kicks off CI Joe builds upon new commits. Useful for CI Joe servers running behind a firewall.
require 'yaml'
require 'net/http'
PROJECT_PATH = '/Users/mbuck/src/applicant_portal/hr_suite'
PORT = 3000
def current_sha
`cd #{PROJECT_PATH} && git rev-parse origin/master`.chomp
end
def last_built_sha
last_build_file = File.join(PROJECT_PATH, '.git', 'builds', 'last')
current_build_file = File.join(PROJECT_PATH, '.git', 'builds', 'current')
if File.exist?(last_build_file) && !File.exist?(current_build_file)
config = YAML.load(File.read(last_build_file))
return config[4]
end
return false
end
def git_update
`cd #{PROJECT_PATH} && git fetch origin && git reset --hard origin/master`
end
while true
git_update
last = last_built_sha
current = current_sha
if last && (last != current)
Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{PORT.to_s}/"), {'build' => 'now'})
end
sleep 60
end
@techpeace
Copy link
Author

Run this with nohup, a là nohup cijoe_github_poller.rb &

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment