I have the following JSON:
{"defaultOptions" : {"environmentVariableEntries" : [ {"key" : "OS_VERSION","value" : "13" } ] }}on Jenkins I have a step that writes some environment variables and in another step I need to insert those variables to environmentVariableEntries in the json above,here is my code:
sh(script: "echo \$(jq --arg url \"$URL\" '.defaultOptions.environmentVariableEntries += [{\"key\": \"URL\", \"value\": \$url}]' json.xctestplan) > json.xctestplan", returnStdout: true)this kind of works but have 2 issues:
- it adds \n to the end of the replaced URL
- In some cases (special character ?) it throws:
++ jq --arg url 'https://redacted''.defaultOptions.environmentVariableEntries += [{"key": "URL", "value": [$url]}]' json.xctestplanjq: parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 2, column 1+ echoI tried to wrap the variable in [] without success.