Skip to content

Instantly share code, notes, and snippets.

@pjfitzgibbons
Created October 5, 2011 14:51
Show Gist options
  • Save pjfitzgibbons/1264615 to your computer and use it in GitHub Desktop.
Save pjfitzgibbons/1264615 to your computer and use it in GitHub Desktop.
git post-receive for conditional Jenkins run
#!/usr/bin/env ruby
require '~/bin/webapp-post-receive'
old_head, new_head, ref = STDIN.gets.split
redmine_project = 'redmine-project-name'
ci_project = 'jenkins-project-name'
WebappPostReceive.process(:redmine_project => redmine_project,
:ci_project => ci_project,
:build_with_parameters => false,
:ci_branch => 'development',
:old_head => old_head,
:new_head => new_head,
:ref => ref)
class WebappPostReceive
def self.process(opts)
puts "Input Opts are : #{opts.inspect} "
old_head = opts.delete :old_head
new_head = opts.delete :new_head
ref = opts.delete :ref
ref =~ /refs\/heads\/(.*)/
branch = $1
puts "old_head: #{old_head}"
puts "new_head: #{new_head}"
puts "ref: #{ref}"
puts "branch: #{branch}"
redmine_repository_api_key = "tV9z6GqZGykY1pRVDiFW"
glog = `git log -1 --stat #{new_head}`
# if (glog =~ /1 files changed/ && glog =~ /VERSION/ && glog =~ /Version bump/)
# || (glog =~ /1 files changed/ && glog =~ /CHANGELOG/ && glog =~ /Collect Changelog/)
if (glog =~ /Jenkins|Hudson/)
puts "Skipping CI-invoked push of VERSION and Tagging"
exit
end
redmine_project = opts[:redmine_project]
ci_project = opts[:ci_project]
ci_branch = opts[:ci_branch] || 'master'
build_with_parameters = true # default
build_with_parameters = opts[:build_with_parameters] if opts.key?(:build_with_parameters)
ci_url = opts[:ci_url] || "default_host:8080"
redmine_url=%Q("http://redmine_server.local/sys/fetch_changesets?id=#{redmine_project}&key=#{redmine_repository_api_key}")
if build_with_parameters
hudson_url=%Q("http://#{ci_url}/job/#{ci_project}/buildWithParameters?delay=0sec&GIT_BRANCH=#{branch}")
else
hudson_url=%Q("http://#{ci_url}/job/#{ci_project}/build")
end
puts "Backgrounding...
Redmine Repository processing
... #{redmine_url}
"
if branch != ci_branch
puts "Branch is #{branch}
... Hudson will only build for commits to #{ci_branch} !!!
... Have a nice day :)
"
else
puts "CI Build
... #{hudson_url}
... watch the console at: http://#{ci_url}/job/#{ci_project}/lastBuild/console
WAKEUP!! Git Pull after Successful Build for updated VERSION file and Git tags
(so sorry to yell... just needed your attention there ;)
"
end
fork do
`wget #{redmine_url} -o #{redmine_project}-redmine-refresh.html`
end
if branch == ci_branch
fork do
`wget #{hudson_url} -o #{ci_project}-hudson-build.html`
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment