我尝试使用chef安装OpenJDK,以及在Windows 2008节点上使用p2 director安装Eclipse并安装一些插件。 OpenJDK安装并设置我的环境变量JAVA_HOME并将其添加到路径中。 但是,在我关闭并重新打开PowerShell之前,此更改不会生效。厨师 - 客户端运行需要在当前会话中运行eclipse p2导演。有没有办法做到这一点,我只能运行一次厨师 - 客户端?
在我安装openJDK的方法中,我包括:
env "JAVA_HOME" do
value 'C:\\Program Files\\Zulu\\zulu-8'
end
env "path" do
delim ";"
value '%JAVA_HOME%\\bin'
action :modify
end
#For Command Prompt
execute "setPathCMD" do
command "set PATH=#{node['java']['path']}\\bin;%PATH%"
end
#For PowerShell
powershell_script "setPathPS" do
code <<-EOH
$env:Path="#{node['java']['path']}\\bin;$env:Path"
EOH
end
ENV['Path'] += ";C:\\Program Files\\Zulu\\zulu-8\\bin"
在安装eclipse插件的方法中,我有:
if not node['eclipse']['plugins'].empty?
node['eclipse']['plugins'].each do |plugin_group|
repo, id = plugin_group.first
execute "eclipse plugin install" do
command "#{node['eclipse']['unzip_location']}/eclipse/eclipse.exe -application org.eclipse.equinox.p2.director -noSplash -repository #{repo} -installIUs #{id}"
action :run
end
end
end
答案 0 :(得分:1)
尝试使用setx:
execute 'set java_home' do
command "setx -m JAVA_HOME \"C:\\Program Files\\Zulu\\zulu-8\""
only_if { ENV['JAVA_HOME'] != 'C:\\Program Files\\Zulu\\zulu-8' }
end
# Set JAVA_HOME for this process
ENV['JAVA_HOME'] = 'C:\\Program Files\\Zulu\\zulu-8'
# do something similar for path...
改编自visualstudio cookbook以启用NuGet包恢复: https://github.com/daptiv/visualstudio/blob/master/recipes/nuget.rb
答案 1 :(得分:0)
点击client.rb
或solo.rb
:
ENV['VAR'] = 'value'