我在github上有一个scala repo,它在scala.yml
中有scala工作流。我的一项测试需要一把特殊的钥匙。但由于隐私原因,我无法将其硬编码为源代码。因此,我在Settings
中添加了Secrets
部分的密钥。本节说明
Secrets are environment variables that are encrypted and only exposed to selected actions. Anyone with collaborator access to this repository can use these secrets in a workflow.
Secrets are not passed to workflows that are triggered by a pull request from a fork.
但当我尝试在代码中获取密钥时(在测试中(,结果是空白的。
System.getenv("MY_KEY") //MY_KEY is added to the Secrets in Settings of the repo
此外,这个工作流程不是由fork的pull请求触发的
您需要在这里给出的工作流的环境变量中设置它。如果Secrets
中的变量名是MY_KEY
,那么在工作流中,您可以将其作为{{ secrets.MY_KEY }}
访问
示例
- name: Run tests
env:
MY_KEY: ${{ secrets.MY_KEY }}
run: sbt test
这将设置环境变量MY_KEY
,并可通过System.getenv("MY_KEY")
访问