I'm trying to parse a value from a file in order to set it as an attribute for use further down the recipe (to set as a subdirectory name).
The file is downloaded from a jenkins server and parsed in a ruby block to get the value - so far so good. However, if I try to assign that to the node attribute, it doesn't work. I thought I'd found the answer here: How to lazily evaluate an arbitrary variable with Chef, but none of the methods mentioned there work for me. What am I doing wrong?
ruby_block "get build number" do
block do
f = File.open("/tmp/MyappJenkinsBuildInfo.txt")
f.each {|line|
line_arr = line.split('=')
if line_arr[0] == 'jenkins.build.number'
node.default['myapp']['jenkins']['build'] = line_arr[1]
break
end
}
f.close
end
end
build = DelayedEvaluator.new { node['myapp']['jenkins']['build'] }
release_dir = "#{node['myapp']['dir']['main']}/releases/#{build.call}"
This "works" in that there's no syntax error, but the value of #{build.call} is an empty string. The file definitely exists, and I've already tested that line_arr[1] inside the ruby block is getting the right value (with a puts statement inside the RB). I've also tried using lambda in place of DelayedEvaluator.new.