如何检索gatsby-*。js文件中要使用的gitlab环境变量
我在gitlab环境变量上秘密API令牌,我想在项目中安全加载以在 gatsby - .js*文件中使用。我没有或不想使用 .env 文件。根据各种来源,我应该能够像这样使用我的env变量:process.env.token
,但它不起作用。我尝试了多个盖茨比插件,我尝试将前缀gatsby _
访问Gitlab上的ENV变量,但它仍然不起作用。 我暂时可以做的是在我的 gitlab-ci.yml 文件中检索其值: token:“ $ {gatsby_token}”
我可以在我的构建阶段回荡它们,因此我不知道该值在我的yml文件中是否可在我的yml文件中获得可观,否则只有在管道为pipeline时才能使其变得可观在Gitlab上推出。我的问题是可以将它们传递给我的盖茨比 - *。js文件吗?还是完全解决了问题?
I have on gitlab environment variables secret api tokens, that I want to securely load in my project to be used in the gatsby-.js* files. I do not have or want to use .env files. According to various sources, I should be able to use my env variables just like this : process.env.TOKEN
, but it does not work. I tried multiple Gatsby plugins, I tried having the prefix GATSBY_
to my env variables on gitlab, yet it still doesn't work.
What I was able to do for now is to retrieve their values in my gitlab-ci.yml file like this :TOKEN: "${GATSBY_TOKEN}"
where I can echo them in my build stage, So I don't know if the value is accesible in my yml file locally or it only becomes accesible when the pipeline is launched on gitlab. My question is it possible to pass them down to my gatsby-*.js files ? Or is there another solution entirely to the problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是环境变量应该使用的方式。
如果您不想使用
.env
文件,您唯一的机会就是在运行命令中设置它们,gatsby开发
以及gatsby build
:从现在开始,
some_env_var
将暴露在代码中使用。That is not how environment variables are supposed to work.
If you don't want to use
.env
files your only chance is setting them in the running commands,gatsby develop
as well asgatsby build
:From now on,
SOME_ENV_VAR
will be exposed to be used in your code.