【发布时间】:2023-02-24 03:13:08
【问题描述】:
Github 操作:如何使用 Github 存储库机密编辑 JSON 对象在我的工作流程中,我的工作是编辑 json 文件中的空 JSON 值,并将它们替换为我的 github 秘密。问题是当我运行 cat 'test.json' 命令时,我的更新值没有出现:
JSON 文件:
{
"secret": "",
"name": "test"
}
工作流程:
steps:
- name: Edit Json
shell: bash
run: |
echo "`jq '.secret="${{ secrets.PRIVATE_KEY }}"'test.json`" > test.json
- name: display
run: |
cat 'test.json'
输出:
{
"secret": "",
"name": "test"
}
预期输出:
{
"secret": "****************",
"name": "test"
}
【问题讨论】:
-
尝试:
jq '.secret = "${{ secrets.PRIVATE_KEY }}"' test.json > test.out.json,然后是cat test.out.json。 -
请考虑使用现有的 github 操作来更新该值,例如 github.com/jossef/action-set-json-field
-
这个秘密被编辑了,它永远不会被打印出来。要进行测试,您可以以某种方式修改它,例如,对其进行 base64 编码,然后查看该值是否看起来正确。
标签: json github github-actions