Search code examples
groovyazure-automation

How to send parameters to Azure runbook api


We are using Azure automation and groovy script from Scriptrunner to create different jobs based on different Runbook

For that we are using the following API call sample

http.request(PUT) {
            requestContentType = ContentType.JSON
            headers.'Authorization' = "Bearer " + AuthToken 
            body = ['properties': ['runbook': ['name': Runbook],'parameters':['Vm': Env], 'runOn': 'devops']]

The way we format the body here is working ok when we need to hard code a single parameter named Vm in our case which set from an Env parameter string

The issue we met actually is that this parameters section of the body can have more than 1 single parameters and different parameter name.

For example the following body can be possible too depending on different use case :

body = ['properties': ['runbook': ['name': Runbook],'parameters':[**'Vm': Env, 'Path': absolute, 'Target':test01**], 'runOn': 'devops']]

What I am trying to do, is to build the parameters section has a variable that I can then place as part of the body as bellow

body = ['properties': ['runbook': ['name': Runbook],'parameters':[$paramList], 'runOn': 'devops']]

$paramList is a string which contains "'Vm': Env, 'Path': absolute, 'Target':test01"

For some reason it does not work, what did I miss on building that string and injecting in the parameters section of the body value ?

Thanks for help regards


Solution

  • The solution as explain by @cfrick was to use Map object as below. I need to define my dynamique parameters as :

    Map myParams=['Vm1': Env1,'Vm2': Env2]
    

    Then injecte the Map object as part of the global body :

    body = ['properties': ['runbook': ['name': Runbook],'parameters':myParams, 'runOn': 'devops']]