Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

Correctly escape environment variable to be used in Jenkins jq script

$
0
0

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+ echo

I tried to wrap the variable in [] without success.


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>