github - Environtment variable via github secrets
问题描述
I have a scala repo on github with has the scala work flow in scala.yml
. One of my test requires a special key to be available. But I can't hard code it into source code because of privacy reasons. So, I added the key to Secrets
section in Settings
. The section states
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.
But when I do try to get the key in my code(in the test) it comes out as blank.
System.getenv("MY_KEY") //MY_KEY is added to the Secrets in Settings of the repo
Also, this workflow is NOT triggered by a pull request from a fork.
解决方案
您需要将它设置在环境变量中的设置中,您的工作流程如此处给出。如果变量名称在Secrets
工作MY_KEY
流程中,您可以将其访问为{{ secrets.MY_KEY }}
例子
- name: Run tests
env:
MY_KEY: ${{ secrets.MY_KEY }}
run: sbt test
这将设置环境变量MY_KEY
并且可以通过System.getenv("MY_KEY")
推荐阅读
- javascript - 为什么clickHandler中的this关键字未定义?
- angular - 如何在 Angular 路由上集成淡入淡出效果
- precision - 如何正确使用 Kaitai-Struct 解码这些数据?
- javascript - 无需单击下一步按钮即可切换 HTML 表单
- javascript - JS Pig诗匹配子字符串与正则表达式
- java - 如何在LinearLayout中的TextView下方显示ImageView
- html - 如何将文本移动到 html 复选框的左侧?
- react-native - 反应原生 eslint 预提交不起作用
- javascript - 如何将 acf 关系填充到 resful api?
- c# - 来自外部 *.dll 的 WPF 数据绑定属性