Node.js 使用CircleCI部署到Firebase主机

Node.js 使用CircleCI部署到Firebase主机,node.js,continuous-integration,firebase,circleci,Node.js,Continuous Integration,Firebase,Circleci,我试图弄清楚如何使用CircleCI部署到Firebase主机。据我所知,无法使用SSH密钥设置部署,因此我试图找到一种在部署期间登录Firebase并推送代码的方法。到目前为止,我在我的圈子里尝试了以下内容。yml: // circle.yml deployment: production: branch: circle-deploy commands: - npm install -g firebase-tools - firebase login

我试图弄清楚如何使用CircleCI部署到Firebase主机。据我所知,无法使用SSH密钥设置部署,因此我试图找到一种在部署期间登录Firebase并推送代码的方法。到目前为止,我在我的圈子里尝试了以下内容。yml:

// circle.yml
deployment:
  production:
    branch: circle-deploy
    commands:
      - npm install -g firebase-tools
      - firebase login | echo -e "${FIREBASE_EMAIL}\n${FIREBASE_PASSWORD}"
      - firebase deploy
然而,我不断得到以下错误,我不知道如何补救它

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: write EPIPE
    at errnoException (net.js:904:11)
at Object.afterWrite (net.js:720:19)

以下是我们部署到CircleCi所遵循的流程

  • 将用户名和密码作为项目级别的环境变量存储在CircleCi中

  • 编辑你的circle.yml

    deployment:
      production:
        branch: your_branch
        commands:
          - npm install -g firebase-tools
          - firebase login --email $FIREBASE_USERNAME --password $FIREBASE_PASSWORD
          - firebase deploy
    
    general:
      branches:
        only:
          - master
    
    test:
      override:
        - echo "test"
    
    deployment:
      production:
        branch: master
        commands:
          - npm install -g firebase-tools
          - firebase deploy --token=$FIREBASE_TOKEN --non-interactive
    
  • 推到你的分支


  • 看起来不错。

    我只是不得不这么做,还有一个更简单的方法

  • 在您的计算机上,您可以通过键入

    firebase login:ci
    
  • 将该令牌另存为circleci中的环境变量,
    $FIREBASE\u token
  • 对于部署步骤,您可以跳过登录:

    deployment:
      production:
        branch: master
        commands:
          - firebase deploy --token=$FIREBASE_TOKEN --non-interactive
    

  • 对于其他偶然发现这个问题的人,我必须采取以下步骤让CircleCI(可能还有其他CI)与Firebase主机一起工作

  • 生成CI令牌:
    firebase登录:CI
  • 将该令牌另存为ENV var(
    FIREBASE\u令牌
  • 在部署脚本中使用令牌:
    firebase部署--token=$firebase\u token--非交互式

  • Firebase最近添加了
    登录:ci
    ,以防止人们将个人部署令牌用于ci服务。

    上述其他答案的一个小补充

    为了避免在每次构建时在circle ci中全局安装firebase工具:

    修改package.json文件,将firebase工具作为开发人员依赖项包括在内,如下所示:

    npm install --save-dev firebase-tools
    
    然后在circle.yml文件中:

    deployment:
      production:
        branch: master
        commands:
          - ./node_modules/.bin/firebase deploy --token=$FIREBASE_TOKEN --non-interactive
    

    这是我的初始设置,仅部署主测试,跳过测试

  • 在本地计算机上运行npm安装-g firebase tools
  • 运行firebase login:ci在本地计算机上获取令牌
  • 运行firebase init。这将创建firebase.json并确保它已提交
  • 在circileci上项目的生成设置中的环境变量中配置FIREBASE\u令牌
  • //circle.yml

    deployment:
      production:
        branch: your_branch
        commands:
          - npm install -g firebase-tools
          - firebase login --email $FIREBASE_USERNAME --password $FIREBASE_PASSWORD
          - firebase deploy
    
    general:
      branches:
        only:
          - master
    
    test:
      override:
        - echo "test"
    
    deployment:
      production:
        branch: master
        commands:
          - npm install -g firebase-tools
          - firebase deploy --token=$FIREBASE_TOKEN --non-interactive
    

    不知道登录:ci是件事。谢谢你指出这一点!