简体   繁体   中英

Reading a specific yaml value using Groovy

I have this yaml config file:

environmentMapping:
 ci-develop:
   inner: ABCD-npr-XA
   outer: ABCD-npr-XB
   outer-public: ABCD-npr-XC
   frontend: ABCD-npr-XD
 dev-develop:
   inner: BCDE-npr-ZA
   outer: BCDE-npr-ZB
   outer-public: BCDE-npr-ZC
   frontend: BCDE-npr-ZD 

And would like to know how I can access a specific value.

here's my code:

  configs = readYaml file: 'configs.yaml'
  def env = 'ci-develop'
  def zone = 'inner'
  echo configs.environmentMapping.${env}.${zone}

This does not work.

How can I get the value for ci-develop -> inner?

configs = readYaml file: 'configs.yaml'
def env = 'ci-develop'
def zone = 'inner'

echo configs.environmentMapping[env][zone]

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