如何在CI过程中设置vue_app_variable azure devops

发布于 2025-02-13 12:39:45 字数 462 浏览 1 评论 0原文

在代码中使用vuejs 2.x,我想使用这样的环境变量:

callApi(process.env.VUE_APP_API_KEY)

问题是:我想在Azure DevOps的CI过程中设置此vue_app_api_key的值,但我的解决方案不起作用。

我做了什么:

  1. 在管道变量中创建一个变量名称api_key。

  2. 尝试在此任务期间设置值

- task: CmdLine@2
  displayName: Build application
  inputs:
    script: yarn build
  env:
    VUE_APP_API_KEY: $(API_KEY)

有人知道我的解决方案有什么问题以及如何正确地做到这一点?

谢谢

I'm using VueJS 2.x

In my code, I want to use an environment variable like this:

callApi(process.env.VUE_APP_API_KEY)

The problem is: I want to set the value of this VUE_APP_API_KEY during the CI process in Azure DevOps but my solution doesn't work.

What I have done:

  1. Create a variable name API_KEY in pipeline variables.

  2. Try to set the value during this task

- task: CmdLine@2
  displayName: Build application
  inputs:
    script: yarn build
  env:
    VUE_APP_API_KEY: $(API_KEY)

Does anyone know what wrong with my solution and how to do it the right way?

Thank you

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

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

发布评论

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

评论(2

千秋岁 2025-02-20 12:39:46

我已经测试了您的YAML脚本以设置变量的值,并且可以输出我设置的值。

  - task: CmdLine@2
    displayName: Build application
    inputs:
      script: echo $VUE_APP_API_KEY
    env:
      VUE_APP_API_KEY: $(API_KEY)

您可以参考此文档有关命令链接任务的有关设置变量的更多信息。

I have tested your YAML script to set the value of the variable and it could output the value I have set.

  - task: CmdLine@2
    displayName: Build application
    inputs:
      script: echo $VUE_APP_API_KEY
    env:
      VUE_APP_API_KEY: $(API_KEY)

You could refer to this document for more information about set variable with command link task.

缘字诀 2025-02-20 12:39:45

假设您正在使用WebPack构建应用程序,则必须手动注入您的env vars:

通过WebPack中的环境依赖变量

Assuming you are building your application using Webpack, you have to inject your env vars manually:

Passing environment-dependent variables in webpack

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