2
votes

I am trying to parse a groovy file using config slurper like this .

fileContents = '''deployment {
  deployTo('dev') {
test = me
  }
  }'''
def config = new ConfigSlurper().parse(fileContents)

The above code works because the deployto('dev') is simply accepting a string. But I add an extra parameter to it , it fails with this exception:

fileContents = '''deployment {
  deployTo('dev','qa') {
test = me
  }
  }'''
def config = new ConfigSlurper().parse(fileContents)

It fails with the following exception :

Caught: groovy.lang.MissingMethodException: No signature of method: groovy.util.ConfigSlurper$_parse_closure5.deployTo() is applicable for argument types: (java.lang.String, java.lang.String, script15047332444361539770645$_run_closure3$_closure10) values: [dev, postRun, script15047332444361539770645$_run_closure3$_closure10@6b8ca3c8]

Is there a way around reading this config file with extra args in a module?

1
Ishu, please check the solution to see if that resolves. - Rao

1 Answers

1
votes

You are almost there. In order to use list of values, please do the below change.

From:

deployTo('dev','qa')

To:

deployTo(['dev','qa'])

It would be:

def fileContents = '''deployment {   deployTo(['dev','qa']) { test = me   }   }''' 
def config = new ConfigSlurper().parse(fileContents)​