Skip to content

Commit e54be3d

Browse files
author
Kevin Paulisse
committed
Run puppet version detector in a clean environment
1 parent 8e14d69 commit e54be3d

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

lib/octocatalog-diff/util/puppetversion.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ def self.puppet_version(puppet)
1515
raise ArgumentError, 'Puppet binary was not supplied' if puppet.nil?
1616
raise Errno::ENOENT, "Puppet binary #{puppet} doesn't exist" unless File.file?(puppet)
1717
cmdline = [Shellwords.escape(puppet), '--version'].join(' ')
18-
output, _code = Open3.capture2e(cmdline)
19-
return Regexp.last_match(1) if output =~ /^([\d\.]+)\s*$/
20-
raise "Unable to determine Puppet version: #{output}"
18+
19+
# This is the environment provided to the puppet command.
20+
env = {
21+
'HOME' => ENV['HOME'],
22+
'PATH' => ENV['PATH'],
23+
'PWD' => File.dirname(puppet)
24+
}
25+
out, err, _status = Open3.capture3(env, cmdline, unsetenv_others: true, chdir: env['PWD'])
26+
return Regexp.last_match(1) if out =~ /^([\d\.]+)\s*$/
27+
raise "Unable to determine Puppet version: #{out} #{err}"
2128
end
2229
end
2330
end

0 commit comments

Comments
 (0)