简体   繁体   中英

Chef - Local variables within ruby_block

First time using chef/ruby

buildNumber = String.new

ruby_block 'test' do
  block do
    def parse_xml
      buildNumber = "123"
    end

    parse_xml do
    end

    print "buildNumber is: " +buildNumber
  end
  action :run
end

I want the line print "buildNumber is: " +buildNumber to print out 123 and not blank, how can I achieve this?

I put the whole thing in a begin-end block as follows and it worked.

buildNumber = String.new
    ruby_block 'test' do
      block do
      begin
    buildNumber = "123"
    end

    print "buildNumber is: " +buildNumber
      end
      action :run
    end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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