英文:
Gilab-ci pipeline not resolving variables not resolved when there is a double quotes inside single quote
问题
The command to resolve the GitLab variable within your GitLab CI/CD script should be as follows:
jq -r ".version |= \"$TAG\"" temp.json > package.json
This command uses double quotes to properly substitute the value of the $TAG
variable within the jq
command.
英文:
I'm trying to change a version of package.json with git TAG generated using jq
. For that I need to use double quotes inside a single quote passing a gitlab variable as parameter.
The command is jq -r '.version |= "${TAG}"' temp.json > package.json
but the ${TAG} or $TAG is not resolving to its value.
build-cloudfront:
stage: build
image: node:18
variables:
TAG: $CI_COMMIT_TAG
script:
- apt-get update
- apt-get install jq -y
- mv package.json temp.json
- jq -r '.version |= "${TAG}"' temp.json > package.json
- npm install
- npm run build
- echo "FRONTEND BUILD SUCCESSFULY"
artifacts:
paths:
- dist/
expire_in: "10 mins"
# Run this job for tags
only:
- tags
Resolve gitlab variable.
答案1
得分: 0
以下是翻译好的内容:
要在 jq 的过滤器中使用 bash 变量,你需要将该变量绑定为参数,例如 --arg name $variable
或 --argjson name JSON-text
(jq 手册)
在你的情况下,你可以这样写:
jq -r --arg TEMP_TAG "$TAG" '.version |= "${TEMP_TAG}"' temp.json > package.json
更多问题和可能的重复问题:
https://stackoverflow.com/questions/40027395/passing-bash-variable-to-jq
英文:
For using a bash-variable in jq's filter you need to bind the variable as argument e.g. --arg name $variable
or --argjson name JSON-text
(jq manual)
In your case you could write following.
jq -r --arg TEMP_TAG "$TAG" '.version |= "${TEMP_TAG}"' temp.json > package.json
futher question and possible duplicate question:
https://stackoverflow.com/questions/40027395/passing-bash-variable-to-jq
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论