firebase - 如何通过 CI 部署到特定的 Firebase 托管服务?出现“参数过多”错误
问题描述
我正在尝试设置一个 CI 来通过 GitLab 构建和部署我的网站。我的网站托管在 Firebase 上。
我已经设置了一个子域进行测试,因此它不会干扰生产站点。
我可以firebase deploy --only hosting:test --message "Release: $PACKAGE_VERSION"
在本地机器上使用该命令,没有问题。
当我将其更改为它时,它会在运行 CI 时firebase deploy --token $FIREBASE_TOKEN --only hosting:test --message "Release: $PACKAGE_VERSION"
给我一个错误。Too many arguments
我怎样才能让它工作?
我的开发依赖项中的 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! admiralfeb-net@2019.3.1 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 admiralfeb-net@2019.3.1 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 中,您的环境变量有一个受保护的选项。这会将它们隐藏在未在受保护标签或分支上运行的管道中。我检查了这个选项。
取消选中受保护的选项并重新运行管道。我还从部署调用中删除了 --token 变量。如果令牌在环境中并被调用,Firebase 将使用令牌FIREBASE_TOKEN
。
推荐阅读
- winapi - 为什么 GetFileAttributesA() 与 unix 目录路径分隔符一起使用?
- python-3.x - OpenCV 图像去噪给出:错误:-215:断言失败
- android - 错误 MSB4064:“XamarinDownloadArchives”任务不支持“AllowUnsecureUrls”参数
- mysql - 复合键 - 自动增量问题 / InnoDB MySQL 表
- c# - Azure 服务总线规则名称最大长度
- jquery - Jquery在输入的每两个字符更改时调用一个函数
- javascript - findOneAndUpdate 仅提供部分更新
- c++ - 删除全局隐式函数 - 避免模棱两可的运算符
- angular - Twin 订阅 block forkJoin 订阅
- sql - 如何根据分组将字符串组合在一列中