[英]How do I get all GitHub secrets into env variables for Actions to access (powershell in my case)?
I read some similar posts but none seem to answer this question.我读了一些类似的帖子,但似乎没有人回答这个问题。 I can set individual GitHub secrets into environment variables in an Action if I know the name of the secret: env: PW_ID0007: "${{secrets.PW_ID0007}}" How can I expose all secrets as environment variables without knowing their names (either in bulk or some way to iterate through them and set them individually?)如果我知道秘密的名称,我可以将单个 GitHub 秘密设置为操作中的环境变量: env: PW_ID0007: "${{secrets.PW_ID0007}}" 如何在不知道其名称的情况下将所有秘密公开为环境变量(或者批量或以某种方式遍历它们并单独设置它们?)
There is a way to do that.有办法做到这一点。 Please check here请在这里查看
- name: view the secrets context
shell: bash
run: echo "$SECRETS_CONTEXT"
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}
In that way you will expose all secrets without knowing names:这样,您将在不知道名称的情况下公开所有秘密:
And know what you need is go through this json using for instance jq and set them as env variable suing following syntax:并且知道您需要的是使用例如 jq 浏览此 json 并将它们设置为使用以下语法的 env 变量:
echo "variable_name=variable_value" >> $GITHUB_ENV
I created an action exactly for that - takes all the secrets and exports them to environment variables.我为此创建了一个动作 - 获取所有秘密并将它们导出到环境变量。
An example would be:一个例子是:
- run: echo "Value of MY_SECRET1: $MY_SECRET1"
env:
MY_SECRET1: ${{ secrets.MY_SECRET1 }}
MY_SECRET2: ${{ secrets.MY_SECRET2 }}
MY_SECRET3: ${{ secrets.MY_SECRET3 }}
MY_SECRET4: ${{ secrets.MY_SECRET4 }}
MY_SECRET5: ${{ secrets.MY_SECRET5 }}
MY_SECRET6: ${{ secrets.MY_SECRET6 }}
...
You could convert it to:您可以将其转换为:
- uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(secrets) }}
- run: echo "Value of MY_SECRET1: $MY_SECRET1"
Link to the action, which contains more documentation about configuration: https://github.com/oNaiPs/secrets-to-env-action链接到操作,其中包含有关配置的更多文档: https ://github.com/oNaiPs/secrets-to-env-action
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.