AzureDevops passing $`` instead of $() into jq arg via taskgroup

40 Views Asked by At

I currently have the following in my taskgroup bash script

jq --argjson timestamp "$`date +%s`" '.common |= . + {"TimeValue": $timestamp }' ${service}/${env}.json > tmpfile && mv tmpfile ${service}/${env}.json

my issue is with this part

"$`date +%s`"

when the task runs I get the following error

jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,

So if I edit the existing release and change it to the following everything works:

"$(date +%s)"

The problem is when I change to the above in my taskgroup it now thinks that I am trying to add a new parameter which I do not want.

How can I solve this?

1

There are 1 best solutions below

1
Bright Ran-MSFT On BEST ANSWER

You can change to like as one of the below ways.

jq --argjson timestamp `date +%s` '.common |= . + {"TimeValue": $timestamp }' ${service}/${env}.json > tmpfile && mv tmpfile ${service}/${env}.json

OR

timestamp=`date +%s`
jq --argjson timestamp $timestamp '.common |= . + {"TimeValue": $timestamp }' ${service}/${env}.json > tmpfile && mv tmpfile ${service}/${env}.json