Closed pavanfhw closed 3 years ago
I tried something similar on a standalone install with a core.local command to run a curl to invoke a ST2 command (which needed a JSON).
task1:
action: core.local
input:
cmd: "curl -X POST -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'Connection: keep-alive' -H 'X-Auth-Token: token...' -H 'content-type: application/json' -H 'Content-Length: 137' --data-binary '{\"action\": \"core.local\", \"cmd\": \"echo ponies\"}, \"user\": null}' http://127.0.0.1:9101/v1/executions"
So I'm using " around the whole cmd, and then escaping any " within. Then when it comes to the data-binary I am using '.
So this should mean I think for your first example you could use:
input:
cmd: "command --json= '{\"key1\": \"someValeu\", \"key\": \"secondValue\" }' "
I also confirmed that with the above example I could then also put in variables into the command, e.g. ''' cmd: "curl -X POST -H 'Accept-Encoding: gzip, deflate' -H 'Accept: /' -H 'Connection: keep-alive' -H 'X-Auth-Token: token...' -H 'content-type: application/json' -H 'Content-Length: 137' --data-binary '{\"action\": \"core.local\", \"cmd\": \"echo ponies<% ctx().key %>\"}, \"user\": null}' http://127.0.0.1:9101/v1/executions" ''' and it then replaced <% ctx().key %> with its variable (where key was in this case a parameter to the workflow).
Could you try using the above syntax with the " after the cmd:" and the extra escapes on the ", and see if that resolves your problem.
@amanda11 Using your syntax everything worked as I wanted. Thank you for the solution!
SUMMARY
I need to insert a workflow parameter inside a Json definition for my action. The first problem is that I can't even run the command with a Json definition in it (withou the parameter in the Json).
This results in the error:
The second problem is, assuming I can resolve the first one, as far as I saw in the examples and tested,
<% ctx().parameter %>
cannot be used inside single quotes, it only works when used inside double quotes. But the Json only works if I define it using single quotes. In the end I would like to have the workflow:STACKSTORM VERSION
st2 3.4dev (c422f0029), on Python 3.6.9
OS, environment, install method
Running on Kubenetes on k3os system. Deployed using stackstorm-ha
Expected Results
Is there a way to get around these problems?