Skip to content
This repository

Fixing Munge of ENV #54

Merged
merged 1 commit into from almost 3 years ago

6 participants

John Kamenik nt Josh Owens Coverall Crew Jacqui Maher Daniel Doubrovkine (dB.) @dblockdotorg
John Kamenik

I had a problem where all the builds started to fail except the first after a CIJoe restart. I traced the problem to the munging of the ENV when a hook is called. I have slightly modified the run_hook function to provide a clean ENV to the hook file, but to reinstate the ENV for the next build.

nt
nt commented May 17, 2011

Hello @jkamenik,

I am currently runnin into some trouble with my CI Joe setup. It looks like the same bug you encountered. Could you confirm please ?

http://stackoverflow.com/questions/6030840/rails-dependency-problem-within-ci-joe

Thank you,

Nicolas.

John Kamenik

Your setup seems to be similar to mine. I was using RVM, but because the ENV pollution it would not stay clean CIJoe would only checkout and build 1 time then it would crash. My ci command was rvm use 1.8.7@gemset; bundle install; rake spec. After the first build the gem set would be wrong and cijoe could not handle it. Cleaning the ENV prevents ENV changes from effecting CIJoe.

Josh Owens
Collaborator
queso commented May 17, 2011

hey guys,

Thanks for sending in the pull request, I will try to get this tested and merged in the next day or so.

nt
nt commented May 18, 2011

Thanks @jkamenik. I tried your patch, it worked like a breeze. I'm up and running :)
Cheers from France.

Coverall Crew

Ah, this is just what I need! Hope this gets merged in :)

Jacqui Maher
jacqui commented May 25, 2011

Yes please!

Daniel Doubrovkine (dB.) @dblockdotorg
dblock commented June 11, 2011

+1 fixes it for me

Josh Owens queso merged commit 7c7ea5d into from June 22, 2011
Josh Owens queso closed this June 22, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 15, 2011
John Kamenik Fixed the munging of the env problem that was causing some builds to …
…fail.
91441d5
This page is out of date. Refresh to see the latest.
7  lib/cijoe.rb
@@ -189,9 +189,14 @@ def run_hook(hook)
189 189
           {}
190 190
         end
191 191
 
  192
+      orig_ENV = ENV.to_hash
192 193
       ENV.clear
193 194
       data.each{ |k, v| ENV[k] = v }
194  
-      `cd #{@project_path} && sh #{file}`
  195
+      output = `cd #{@project_path} && sh #{file}`
  196
+      
  197
+      ENV.clear
  198
+      orig_ENV.to_hash.each{ |k, v| ENV[k] = v}
  199
+      output
195 200
     end
196 201
   end
197 202
 
81  test/test_hooks.rb
... ...
@@ -0,0 +1,81 @@
  1
+require 'helper'
  2
+
  3
+# mock files to true
  4
+class File
  5
+  class << self
  6
+    alias orig_exists? exists?
  7
+    alias orig_executable? executable?
  8
+    
  9
+    def exists?(f)
  10
+      return true if $hook_override
  11
+      orig_exists? f
  12
+    end
  13
+    def executable?(f)
  14
+      return true if $hook_override
  15
+      orig_executable? f
  16
+    end
  17
+  end
  18
+end
  19
+
  20
+# #mock file to be the file I want
  21
+class CIJoe
  22
+  attr_writer :last_build
  23
+  alias orig_path_in_project path_in_project
  24
+  alias orig_git_user_and_project git_user_and_project
  25
+  
  26
+  def path_in_project(f)
  27
+    return '/tmp/test' if $hook_override
  28
+    orig_path_in_project
  29
+  end
  30
+  
  31
+  def git_user_and_project
  32
+    return ['mine','yours'] if $hook_override
  33
+    orig_git_user_and_project
  34
+  end
  35
+end
  36
+
  37
+class CIJoe::Commit
  38
+  attr_writer :raw_commit
  39
+end
  40
+
  41
+
  42
+
  43
+class TestHooks < Test::Unit::TestCase
  44
+  def teardown
  45
+    $hook_override = nil
  46
+  end
  47
+  
  48
+  def setup
  49
+    $hook_override = true
  50
+    open("/tmp/test",'w') do |file|
  51
+      file.write "echo $test\n"
  52
+      file.write "echo $AUTHOR\n"
  53
+      file.write "export test=foo\n"
  54
+    end
  55
+    File.chmod(0777,'/tmp/test')
  56
+    
  57
+    @cijoe = CIJoe.new('/tmp')
  58
+    @cijoe.last_build = CIJoe::Build.new "path", "user", "project", Time.now, Time.now,
  59
+      "deadbeef", :failed, "output", nil
  60
+    @cijoe.last_build.commit.raw_commit = "Author: commit author\nDate: now"
  61
+  end
  62
+  
  63
+  def test_leave_env_intact
  64
+    ENV['AUTHOR'] = 'foo'
  65
+    @cijoe.run_hook("/tmp/test")
  66
+    assert ENV.size != 0, 'ENV is empty but should not be'
  67
+    assert ENV['AUTHOR'] == 'foo', 'ENV munged a value'
  68
+  end
  69
+  
  70
+  def test_empty_hook_env
  71
+    ENV["test"] = 'should not be shown'
  72
+    output = @cijoe.run_hook("/tmp/test")
  73
+    assert_equal "\ncommit author\n", output
  74
+  end
  75
+  
  76
+  def test_hook_munge_env
  77
+    ENV['test'] = 'bar'
  78
+    output = @cijoe.run_hook("/tmp/test")
  79
+    assert ENV['test'] == 'bar'
  80
+  end
  81
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.