Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Restore original environment after each build and hook #68

Open
wants to merge 1 commit into from

3 participants

Andrew Kane Thiago Diniz Miles Z. Sterrett
Andrew Kane

The current code which runs ENV.clear before each hook breaks with RVM.

Thiago Diniz

Thank you, ankane!

It was really helpful!

Miles Z. Sterrett

This was very helpful for me, as well. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 25, 2011
  1. Andrew Kane
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 13 deletions.
  1. +26 −13 lib/cijoe.rb
39 lib/cijoe.rb
View
@@ -117,15 +117,18 @@ def build!(branch=nil)
build.branch = git_branch
write_build 'current', build
- open_pipe("cd #{@project_path} && #{runner_command} 2>&1") do |pipe, pid|
- puts "#{Time.now.to_i}: Building #{build.branch} at #{build.short_sha}: pid=#{pid}"
+ keep_environment do
+ open_pipe("cd #{@project_path} && #{runner_command} 2>&1") do |pipe, pid|
+ puts "#{Time.now.to_i}: Building #{build.branch} at #{build.short_sha}: pid=#{pid}"
- build.pid = pid
- write_build 'current', build
- output = pipe.read
+ build.pid = pid
+ write_build 'current', build
+ output = pipe.read
+ end
+
+ Process.waitpid(build.pid, 1)
end
- Process.waitpid(build.pid, 1)
status = $?.exitstatus.to_i
@current_build = build
puts "#{Time.now.to_i}: Built #{build.short_sha}: status=#{status}"
@@ -176,13 +179,13 @@ def run_hook(hook)
{}
end
- orig_ENV = ENV.to_hash
- ENV.clear
- data.each{ |k, v| ENV[k] = v }
- output = `cd #{@project_path} && sh #{file}`
-
- ENV.clear
- orig_ENV.to_hash.each{ |k, v| ENV[k] = v}
+ output = nil
+
+ keep_environment do
+ data.each{ |k, v| ENV[k] = v }
+ output = `cd #{@project_path} && sh #{file}`
+ end
+
output
end
end
@@ -222,4 +225,14 @@ def repo_config
def read_build(name)
Build.load(path_in_project(".git/builds/#{name}"), @project_path)
end
+
+ def keep_environment(&block)
+ orig_ENV = ENV.to_hash
+
+ yield block
+
+ ENV.clear
+ orig_ENV.each{ |k, v| ENV[k] = v}
+ end
+
end
Something went wrong with that request. Please try again.