Chef-在ruby_块中使用powershell_脚本

Chef-在ruby_块中使用powershell_脚本,ruby,chef-infra,Ruby,Chef Infra,是否可以在ruby_块中使用powershell_脚本? 我希望在聚合阶段而不是编译阶段运行powershell脚本。 当前代码不起作用: ruby_block 'ruby block so that code is run during convergence phase and not compilation phase' do block do buildNumber = "123" powershell_script 'run powershell scri

是否可以在ruby_块中使用powershell_脚本? 我希望在聚合阶段而不是编译阶段运行powershell脚本。 当前代码不起作用:

ruby_block 'ruby block so that code is run during convergence phase and not compilation phase' do
   block do
      buildNumber = "123"
      powershell_script 'run powershell script' do
      environment ({'buildNumber' => buildNumber})
      code "path/to/script/script.ps1"
      end
   end
action :run
end

我知道您可以在ruby_块外的powershell_脚本上使用一个守卫,使其在收敛期间运行,但我需要在ruby块内定义的局部变量buildNumber

以下代码适用于我:

x = Chef::Resource::PowershellScript.new('unzipper script',run_context)
    x.code 'D:/git/chef/cookbooks/java-8-upgrade/unzipper.ps1'
    x.environment ({'buildNumber' => buildNumber})
    x.run_action :run

在简单的情况下,您可能可以使用
powershell\u out
helper方法。对于更复杂的情况,创建自定义资源并使用普通资源。不要使用手动资源调用(
Chef::resource::Foo.new
,因为我们明确不支持它,并且知道它会破坏东西)。

请不要使用它,它在某些情况下确实无法正常工作(例如ChefSpec测试)。嘿,感谢您的回复,昨天问题的评论对我帮助很大。您认为您可以提供一个使用powershell\u的示例吗?我真的不确定从哪里开始,它的工作原理类似于
shell\u out
,除了您提供的字符串是使用powershell而不是cmd.exe运行的,或者是直接运行的。