Class: Kitchen::LifecycleHook::Local
- Includes:
- Kitchen::Logging, ShellOut
- Defined in:
- lib/kitchen/lifecycle_hook/local.rb
Instance Attribute Summary
Attributes inherited from Base
#hook, #lifecycle_hooks, #phase
Instance Method Summary collapse
-
#run ⇒ void
Execute a specific local command hook.
Methods included from Kitchen::Logging
#banner, #debug, #error, #fatal, #info, #warn
Methods included from ShellOut
Methods inherited from Base
#initialize, #logger, #should_run?
Constructor Details
This class inherits a constructor from Kitchen::LifecycleHook::Base
Instance Method Details
#run ⇒ void
This method returns an undefined value.
Execute a specific local command hook.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kitchen/lifecycle_hook/local.rb', line 14 def run state = state_file.read # set up empty user variable user = {} # Set up some environment variables with instance info. environment = { "KITCHEN_INSTANCE_NAME" => instance.name, "KITCHEN_SUITE_NAME" => instance.suite.name, "KITCHEN_PLATFORM_NAME" => instance.platform.name, "KITCHEN_INSTANCE_HOSTNAME" => state[:hostname].to_s, } # If the user specified env vars too, fix them up because symbol keys # make mixlib-shellout sad. hook[:environment]&.each do |k, v| environment[k.to_s] = v.to_s end # add user to user hash for later merging user[:user] = hook[:user] if hook[:user] # Default the cwd to the kitchen root and resolve a relative input cwd against that. cwd = if hook[:cwd] File.(hook[:cwd], config[:kitchen_root]) else config[:kitchen_root] end # Build the options for mixlib-shellout. opts = {}.merge(user).merge(cwd:, environment:) run_command(command, opts) end |