20

我试图弄清楚如何使用 CircleCI 部署到 Firebase 托管。据我所知,没有办法使用 SSH 密钥设置部署,所以我试图找到一种在部署期间登录 Firebase 并推送代码的方法。到目前为止,我在 circle.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)
4

5 回答 5

38

我只需要这样做,还有一种更简单的方法

  1. 在您的机器上,您可以通过键入获取访问令牌

    firebase login:ci
    
  2. 将该令牌保存为circleci中的环境变量,$FIREBASE_TOKEN
  3. 对于您的部署步骤,您可以跳过登录:

    deployment:
      production:
        branch: master
        commands:
          - firebase deploy --token=$FIREBASE_TOKEN --non-interactive
    
于 2015-11-03T20:55:18.923 回答
16

对上面其他答案的一个小补充......

为了避免在每次构建时在循环 ci 中全局安装 firebase-tools:

修改您的 package.json 文件以包含 firebase-tools 作为开发依赖项,如下所示:

npm install --save-dev firebase-tools

然后在你的 circle.yml 文件中:

deployment:
  production:
    branch: master
    commands:
      - ./node_modules/.bin/firebase deploy --token=$FIREBASE_TOKEN --non-interactive
于 2016-04-08T15:59:03.393 回答
7

对于偶然发现这个问题的任何其他人,这些是我必须采取的步骤,以使 CircleCI(以及可能任何其他 CI)与 Firebase 托管一起工作。

  1. 生成 CI 令牌:firebase login:ci
  2. 将该令牌保存为 ENV var ( FIREBASE_TOKEN)
  3. 在部署脚本中使用令牌:firebase deploy --token=$FIREBASE_TOKEN --non-interactive

Firebaselogin:ci最近添加了此功能,以防止人们将个人部署令牌用于 CI 服务。

于 2016-01-21T23:42:42.717 回答
3

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

  1. 在本地机器上运行npm install -g firebase-tools
  2. 运行firebase login:ci以在本地计算机上获取令牌
  3. 运行firebase初始化。这将创建 firebase.json 确保它已提交
  4. 在 circileci 项目的 BUILD SETTINGS 环境变量中配置FIREBASE_TOKEN

//circle.yml

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
于 2016-11-14T23:35:49.923 回答
1

这是我们部署到 CircleCi 所遵循的过程。

  1. 将您的用户名和密码存储为 CircleCi 中项目级别的环境变量。

  2. 编辑你的 circle.yml

    deployment:
      production:
        branch: your_branch
        commands:
          - npm install -g firebase-tools
          - firebase login --email $FIREBASE_USERNAME --password $FIREBASE_PASSWORD
          - firebase deploy
    
  3. 推送到您的分支

似乎工作正常。

于 2015-02-17T22:01:42.193 回答