21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/build_buddy/builder.rb', line 21
def start_build(build_data)
@build_data = build_data
repo_parts = build_data.repo_full_name.split('/')
command = "bash "
env = {
"GIT_REPO_OWNER" => repo_parts[0],
"GIT_REPO_NAME" => repo_parts[1],
"RBENV_DIR" => nil,
"RBENV_VERSION" => nil,
"RBENV_HOOK_PATH" => nil,
"RBENV_ROOT" => nil,
"PATH" => ENV['PATH'].split(':').select { |v| !v.match(/\.rbenv\/versions|Cellar\/rbenv/) }.join(':')
}
case build_data.build_type
when :pull_request
env["GIT_PULL_REQUEST"] = build_data.pull_request.to_s
command += Config.pull_request_build_script
when :master
command += Config.master_build_script
when :release
env["GIT_BRANCH"] = build_data.build_version
command += Config.release_build_script
else
raise "Unknown build type"
end
@build_data.start_time = Time.now.utc
build_log_filename = File.join(Config.build_log_dir,
"build_#{build_data.build_type.to_s}_#{build_data.start_time.strftime('%Y%m%d_%H%M%S')}.log")
@build_data.build_log_filename = build_log_filename
Bundler.with_clean_env do
@pid = Process.spawn(env, command, :pgroup => true, [:out, :err] => build_log_filename)
@gid = Process.getpgid(@pid)
end
info "Running #{File.basename(command)} (pid #{@pid}, gid #{@gid}) : Log #{build_log_filename}"
if @watcher
@watcher.terminate
end
@watcher = Watcher.new(@pid)
@watcher.async.watch_pid
end
|