繁体   English   中英

Chef-从ruby_block中使用powershell_script

[英]Chef - using powershell_script from within ruby_block

是否可以从ruby_block中使用powershell_script? 我想在融合阶段而不是编译阶段运行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_block外部的powershell_script上使用防护措施,以使其在收敛期间运行,但是我需要在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_out帮助程序方法。 对于更复杂的情况,请创建自定义资源并使用常规资源。 不要使用手动资源调用( Chef::Resource::Foo.new因为我们明确不支持此操作,并且知道它会破坏事物)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM