如何在CI过程中设置vue_app_variable azure devops
我
在代码中使用vuejs 2.x,我想使用这样的环境变量:
callApi(process.env.VUE_APP_API_KEY)
问题是:我想在Azure DevOps的CI过程中设置此vue_app_api_key的值,但我的解决方案不起作用。
我做了什么:
在管道变量中创建一个变量名称api_key。
尝试在此任务期间设置值
- 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:
Create a variable name API_KEY in pipeline variables.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经测试了您的YAML脚本以设置变量的值,并且可以输出我设置的值。
您可以参考此文档有关命令链接任务的有关设置变量的更多信息。
I have tested your YAML script to set the value of the variable and it could output the value I have set.
You could refer to this document for more information about set variable with command link task.
假设您正在使用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