带有 netlify.toml 文件的环境变量

发布于 2025-01-20 22:20:23 字数 698 浏览 3 评论 0 原文

当我在仓库上推出某个分支(“下一个”分支)时,我正在尝试设置一个环境变量,目标是我希望仅在此分支中定义此变量。

我已经阅读了Netlify文档,我不知道自己在做什么错

: “> https://docs.netlify.com/configure-builds/file-lase-configuration/

所以我在我的netlify.toml文件中使用了以下代码:

[context.next.environment]
  SITE_BRANCH = "next"

我也尝试了 [context> context。下一个]

我的变量从未出现在过程中

。谢谢

编辑

这是我的 nuxt.config.js 文件:

export default {
  publicRuntimeConfig: {
    SITE_BRANCH: 'process.env.SITE_BRANCH'
  }
}

这是我的 .env 文件:

SITE_BRANCH=next

I'm trying to set a environment variable when I push on a certain branch on my repo (the 'next' branch), the goal is that I want this variable to be defined only in this branch.

I've read the netlify documentation and I have no idea what I'm doing wrong:

https://docs.netlify.com/configure-builds/file-based-configuration/

So I've used the following code in my netlify.toml file:

[context.next.environment]
  SITE_BRANCH = "next"

I also tried [context.next]

My variable never appears in process.env

Does anyone have any idea what I'm doing wrong ? Thanks

EDIT

This is my nuxt.config.js file:

export default {
  publicRuntimeConfig: {
    SITE_BRANCH: 'process.env.SITE_BRANCH'
  }
}

This is my .env file:

SITE_BRANCH=next

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷︶言冷语的世界 2025-01-27 22:20:23

看来语法更像是这样(压痕很重要)

[context."feat/my-cool-branch"]
  SITE_BRANCH = "next"

详细介绍了更多细节。

Looks like the syntax is more like this (indentation is important)

[context."feat/my-cool-branch"]
  SITE_BRANCH = "next"

This part of the documentation goes more into details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文