Hi,
Some context:
To automate builds in Nutanix CALM, from within a jira workflow transition, we have to perform some API calls. With call A, we retreive some variables
FYI: call A: https://server.domain.com:9440/api/nutanix/v3/blueprints/ which allows us to retreive variable "deployment_create_list" amongst others.
With call B, we start the automated build in Nutanix CALM. Parameter deployment_create_list is required.
Call B: https://server.domain.com:9440/api/nutanix/v3/blueprints/.
Issue:
The value that we retreive from the first call for deployment_create_list is a list, not JSON format:
Hi @Véronique
For your requirement, you will need to use the JsonOutput object to convert the List of Maps into a JSON.
You could try something like:-
import groovy.json.JsonOutput
def list = [[field:"A"
, amount:
1000
], [field:
"A"
, amount:
2000
], [field:
"B"
, amount:
3000
], [field:
"C"
, amount:
4000
]]
def
json = JsonOutput.toJson(list.groupBy{it.field}.
collect
{[
'field'
:it.key,
'amount'
:it.value.sum{it.amount}]})
log.warn
"Output: ${json}"
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
I hope this helps to solve your question.
Thank you and Kind regards
Ram
Thank you for your useful reply! It has guided us to the solution :).
deployments_in_bp = groovy.json.JsonOutput.toJson(obj.spec.resources.app_profile_list[0].deployment_create_list);
Have a great day.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Véronique You are awesome!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.