2 answers

1 accepted

Update

Bamboo does not parse variable content in any way, i.e. the content is always just a string. The problem you are encountering is passing a JSON string as a parameter to AWS CloudFormation via the AWS CloudFormation Stack task, which expects those parameters to be passed into the Parameters field as a JSON string in turn, e.g.:

This will yield the same results as passing the unescaped JSON via the AWS Management Console, where the problem does not exist due to its more advanced UI, which accepts each parameter via an individual text input field.

In other words, the escaped JSON input properly ends up in CloudFormation as an unescaped JSON parameter.

Usability Improvements

I realize that this escaping requirement poses a notable usability issue (the Parameters field inline dialog examples have a a small hint that "Reserved JSON characters in Bamboo variable content need to be escaped at runtime", however, it had been missing in the task documentation, and either way this is not easily discovered). I've filed UAA-203 to contemplate how to improve the usability in this regard (suggestions welcome).

Install the Variable tasks for Bamboo add-on (still works in Bamboo 5.12, just go to 'Manage add-ons' and upload it manually).

Add a Variable File reader task to Get the full content of a file and inject it in a variable.

Specify a variable name, e.g. cloudformation.parameters.

Bamboo adds the prefix bamboo, so this variable needs to be referenced as ${bamboo.cloudformation.parameters}.

Specify the file provided in step 1. to read the content from.

Local scope is sufficient for reusing the variable inside the same job. Read the inline help for details on Result or Plan/Deployment scoped variables.

Reference the variable from a subsequent task to access the contained JSON, e.g. place ${bamboo.cloudformation.parameters} into a task's input field.

Limitation

This workaround has the limitation that the included content cannot use Bamboo variables in turn, because Bamboo doesn't yet support nested/recursive expansion of variables - see https://jira.atlassian.com/browse/BAM-8266.

I think regardless of where the inputs are coming from (file, plan variables, etc.), bamboo is still parsing the input before sending it to AWS or any other tool. So the parsing is happening after the value is supplied to the parameters. So I am not sure whether this will still work. I could be wrong but I will still give it a go. Thanks.

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

I've just confirmed that our resp. integration test for the referenced How to still work as documented. Accordingly, the MalformedJsonException you are encountering is hinting on this being caused by an actual JSON syntax error, specifically a missing brace ('Unterminated object') - I can think of the following possible causes:

Hope this helps - if not, could you please make the offending JSON available so that we can try to reproduce this (and of course, feel free to create a support request, if you'd prefer to take this offline)?

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

I was using the quotes (trail and error) to check whether the bamboo will accept the json as string or not. Obviously the json is correct as I have tested directly on AWS cloudformation and validated already even before writing the cloudformation. I have copied the JSON below.

Sorry I am not sure if I have explained you the problem clearly.

There is a parameter in AWS cloudformation which accepts string value. I am passing the json as string value for that parameter and AWS cloudformation accepts as string when I create the stack directly from AWS. But when I do that on bamboo, it determines the string as JSON while parsing and send it across as JSON to AWS instead of string. So I need to make sure I pass the below JSON as string to AWS.

You have encountered an easy to trip over usability flaw with passing nested JSON objects via task fields that expect any input formatted as JSON in turn. The TL;DR is that you need to escape the nested JSON object before passing it inside the JSON task field - I've updated my answer with a more detailed description of the problem and solution.

As mentioned, I realize that this comprises a notable usability issue, sorry you had to discover it the hard way. Unfortunately I'm not quite sure how to address this with a reasonable amount of effort, insofar the Bamboo task UI doesn't offer any UI widgets out of the box that would allow to mirror the more advanced AWS Management Console UI. Regardless, I've filed UAA-203 to contemplate whether there might be any other options to improve on the current approach (suggestions welcome).

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

This approach requires you to have the JIRA administrative rights. The main aim of this article is to help you achieve an organized, easy-to-maintain workflows in your JIRA instance thereby, reducin...