[英]Access env variables in node js app when using gitlab ci cd pipeline
I am using gitlab ci cd pipe line to deploy my application to ubuntu server.我正在使用 gitlab ci cd pipe 线将我的应用程序部署到 ubuntu 服务器。 I have different.env file for local and for dev env and its not a part of git repo (included in gitignore) how to get env variables in my app when deployed to ubuntu server我有本地和开发环境的不同.env 文件,它不是 git 存储库的一部分(包含在 gitignore 中)如何在部署到 ubuntu 服务器时在我的应用程序中获取环境变量
my gitlab-ci.yml我的 gitlab-ci.yml
stages:
- deploy
cache:
paths:
- node_modules/
deploy:
stage: deploy
script:
- npm install
- sudo pm2 delete lknodeapi || true
- sudo pm2 start server.js --name lknodeapi
I guess you are looking for this - Create Variables Gitlab .You can create your environment variables in the ui and then change your gitlab-ci.yml
like below我猜你正在寻找这个 - 创建变量 Gitlab 。你可以在 ui 中创建你的环境变量,然后像下面这样更改你的gitlab-ci.yml
stages:
- deploy
cache:
paths:
- node_modules/
deploy:
stage: deploy
script:
- echo "NGINX_REPO_KEY"=$NGINX_REPO_KEY >> ".env"
- npm install
- sudo pm2 delete lknodeapi || true
- sudo pm2 start server.js --name lknodeapi
This will create a.env file in root folder and put your variables in it.这将在根文件夹中创建一个 .env 文件并将变量放入其中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.