简体   繁体   English

使用 gitlab ci cd 管道时访问节点 js 应用程序中的 env 变量

[英]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.

相关问题 Docker 容器以代码 2 退出,并通过 Gitlab CI/CD 管道将节点应用程序部署到 Digital Ocean - Docker container exits with code 2 with deploying node app to Digital Ocean via Gitlab CI/CD pipeline 如何将 Angular 环境变量传递给 Gitlab CI/CD 管道 - How to pass Angular environment variables to Gitlab CI/CD Pipeline 无法在 node.js 或 react 中访问 Gitlab 环境变量 - Not able to access Gitlab env variables either in node.js or react 在 GitLab CI/CD 中缓存 Node.js 依赖项的便捷方式 - Convenient way to cache Node.js dependencies in GitLab CI/CD .env 文件不在 Heroku CI/CD 中,带有 Gitlab - .env file not in Heroku CI/CD with Gitlab 在 App Engine for CI/CD Pipeline 中的何处存储环境变量? - Where to store environment variables in App Engine for CI/CD Pipeline? Gitlab CI/CD 管道给出 Dockerfile 错误 - Gitlab CI/CD pipeline giving Dockerfile error 如何在Node.js App Heroku中的.env文件中访问变量 - How to access variables in .env file in node.js app heroku 使用服务在 Debian 11 上部署 React 应用程序会在 gitlab 上的 CI/CD 管道中引发无法解释的错误 - Deploying React app on Debian 11 with serve throws unexplainable error in the CI/CD Pipeline on gitlab 如何在节点js中访问laravel env变量? - How to access laravel env variables in node js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM