AzureDevops 通过任务组将 $`` 而不是 $() 传递到 jq arg

问题描述 投票:0回答:1

我的任务组 bash 脚本中目前有以下内容

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

我的问题是这部分

"$`date +%s`"

当任务运行时,我收到以下错误

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

因此,如果我编辑现有版本并将其更改为以下内容,一切都会正常:

"$(date +%s)"

问题是,当我在任务组中更改为上述内容时,它现在认为我正在尝试添加一个我不想要的新参数。

我该如何解决这个问题?

azure-devops jq
1个回答
0
投票

您可以通过以下方式之一更改为喜欢。

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

timestamp=`date +%s`
jq --argjson timestamp $timestamp '.common |= . + {"TimeValue": $timestamp }' ${service}/${env}.json > tmpfile && mv tmpfile ${service}/${env}.json
© www.soinside.com 2019 - 2024. All rights reserved.