firebase - 如何通过 CI 部署到特定的 Firebase 托管服务?出现 "Too many arguments"错误

标签 firebase continuous-integration gitlab continuous-deployment firebase-cli

我正在尝试设置 CI 以通过 GitLab 构建和部署我的网站。我的网站托管在 Firebase 上。

我设置了一个子域用于测试,因此它不会干扰生产站点。

我可以在本地计算机上使用命令 firebase deploy --only Hosting:test --message "Release: $PACKAGE_VERSION" ,没有任何问题。

当我将其更改为 firebase deploy --token $FIREBASE_TOKEN --only Hosting:test --message "Release: $PACKAGE_VERSION" 时,它给了我一个 Too much argument > 运行 CI 时出错。

我怎样才能让它发挥作用?

我的开发依赖项中的 Firebase-tools 版本为 v6.6.0

错误消息:

> firebase deploy --token $FIREBASE_TOKEN --only hosting:test --message 'Version: $npm_package_version'


Error: Too many arguments. Run firebase help deploy for usage instructions
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1071747d7962717c7675723d7e756450222021293e233e21" rel="noreferrer noopener nofollow">[email protected]</a> deploy-test: `firebase deploy --token $FIREBASE_TOKEN --only hosting:test --message 'Version: $npm_package_version'`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="29484d44405b48454f4c4b04474c5d691b191810071a0718" rel="noreferrer noopener nofollow">[email protected]</a> deploy-test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-04-18T03_06_22_853Z-debug.log
ERROR: Job failed: exit code 1

我的 package.json 脚本

"scripts": {
    "ng": "ng",
    "start": "ng serve --host 0.0.0.0",
    "build": "ng build",
    "build-prod": "ng build --prod --aot",
    "test": "ng test --watch=true",
    "test-ci": "ng test --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox",
    "e2e-ci": "ng e2e --protractor-config=e2e/protractor-ci.conf.js",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "deploy-test": "firebase deploy --token $FIREBASE_TOKEN --only hosting:test --message 'Version: $npm_package_version'",
    "deploy-prod": "firebase deploy --token $FIREBASE_TOKEN --only hosting:prod --message 'Version: $npm_package_version'"
  },

我的 gitlab-ci.yml:

image: node:latest

stages:
  - install
  - build
  - deploy-test
  - deploy-prod

install-dependencies:
  stage: install
  cache:
    policy: push
    paths:
      - node_modules/
  script:
    - npm install --quiet
  only:
    changes:
      - package.json

build:
  stage: build
  cache:
    policy: pull
    paths:
      - node_modules/
  script:
    - npm run build-prod
  artifacts:
    expire_in: 1 week
    paths:
      - dist/

deploy-test:
  stage: deploy-test
  environment: 
    name: test
    url: $FIREBASE_URL_TEST
  when: manual
  dependencies:
    - build
  cache:
    policy: pull
    paths:
      - node_modules/
  script:
    - npm run deploy-test

deploy-prod:
  stage: deploy-prod
  environment: 
    name: production
    url: $FIREBASE_URL_PROD
  only: 
   - master
  when: manual
  dependencies:
    - build
  cache:
    policy: pull
    paths:
      - node_modules/
  script:
    - npm run deploy-prod

我的 firebase.json

{
  "hosting": [{
    "target": "prod",
    "public": "dist/admiralfeb-net",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  {
    "target": "test",
    "public": "dist/admiralfeb-net",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }]
}

和我的.firebaserc

{
  "projects": {
    "default": "admiralfebnet"
  },
  "targets": {
    "admiralfebnet": {
      "hosting": {
        "test": [
          "test-admiralfeb"
        ],
        "prod": [
          "admiralfebnet"
        ]
      }
    }
  }
}

最佳答案

经过一两天的斗争,我发现了问题所在。

在 gitlab 中,环境变量有一个 protected 选项。这会将它们隐藏在未在 protected 标签或分支上运行的管道中。我选中了此选项。

取消选中 protected 选项并重新运行管道。我还从部署调用中删除了 --token 变量。如果该 token 位于环境中并且名为 FIREBASE_TOKEN,Firebase 将使用该 token 。

关于firebase - 如何通过 CI 部署到特定的 Firebase 托管服务?出现 "Too many arguments"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55738793/

相关文章:

docker - nginx 的 gitlab 容器代理传递不适用于推送请求

ios - FCM 通知不会出现在 iOS 12 中

continuous-integration - CI 管道中的 Kotlin 代码覆盖率

node.js - 即使文档有几个字段,也无法获取 firestore 文档字段数据

continuous-integration - 设置 TeamCity 以与 ClearCase 配合使用

c# - 我如何以及为什么要设置 C# 构建机器?

powershell - 无法通过 Gitlab Api (v3/v4) 标记/触发 "Merge when pipeline succeeds"

docker - GitLab Runner 使用 Helm Chart - 指向私有(private)仓库

swift - Firebase 规则失败 : permission_denied

android - 如何在 Firebase 云消息传递 (FCM) 中使用深度链接