Created
June 21, 2012 07:38
-
-
Save jyukutyo/2964414 to your computer and use it in GitHub Desktop.
SubversionのコミットフックでJenkinsのジョブを起動する
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
#!/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'net/http' | |
def get_the_latest_changed_file(repos, rev) | |
IO.popen(sprintf('/usr/local/bin/svnlook changed %s -r %s', repos, rev)) {|io| | |
# 最初の行を返す | |
io.gets | |
# 返す文字列は、次のような形式である | |
# A project_name/trunk/vendors/deli/ | |
} | |
end | |
def to_jenkins_job_name(changed_file) | |
/([A-Z]{1,2}\s+)(.+)/ =~ changed_file | |
# project_name/trunk/vendors/deli/という部分だけを取り出す | |
file_path = $2 | |
# trunkという文字列があれば、プロジェクト名をジョブ名とする | |
trunk_index = file_path.index('trunk'); | |
if trunk_index then | |
file_path.slice(0..trunk_index).split('/')[0] | |
else | |
# branchesという文字列があれば、プロジェクト名_ブランチ名をジョブ名とする | |
branch_index = file_path.index('branches'); | |
project_name = file_path[0..branch_index].split('/')[0] | |
branch_name = file_path[branch_index..file_path.length - 1].split('/')[1] | |
project_name + '_' + branch_name | |
end | |
end | |
changed_file = get_the_latest_changed_file(ARGV[0], ARGV[1]) | |
job_name = to_jenkins_job_name(changed_file) | |
Net::HTTP.version_1_2 | |
Net::HTTP.start('xxx.xxx.xxx.xxx', 8080) {|http| | |
response = http.get(sprintf('/job/%s/build?delay=0sec', job_name)) | |
puts response.body | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment