You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在CloudBuild中通过Firebase CLI配置Firebase Hosting自定义域名

解决Firebase Hosting自定义域名的命令行配置方案

Firebase CLI支持通过命令行完成自定义域名的添加操作,你可以将该命令整合到CloudBuild流水线中,具体实现如下:

1. 在CloudBuild流水线中添加域名配置步骤

将firebase hosting:domain:add命令作为独立步骤加入cloudbuild.yaml,适配无交互的CloudBuild运行环境:

# 省略原有其他步骤

- name: gcr.io/$PROJECT_ID/firebase
  args: ['hosting:domain:add', 'your-custom-domain.com', '--project=$PROJECT_ID', '--non-interactive']
  # --non-interactive参数必须添加,避免触发交互验证流程

- name: gcr.io/$PROJECT_ID/firebase
  args: ['deploy', '--project=$PROJECT_ID', '--only=hosting', '-m', 'Pipeline $BUILD_ID, committed by $_COMMIT_USER - $SHORT_SHA']

# 省略后续其他步骤

2. 关键注意事项

  • DNS验证前置:首次添加新域名时,Firebase会生成DNS验证记录,需提前在域名服务商处配置完成,否则命令会执行失败;若域名已完成验证,可直接执行添加操作。
  • 批量添加域名:如需绑定多个域名,可在参数中依次列出,示例:
    args: ['hosting:domain:add', 'domain1.com', 'domain2.com', '--project=$PROJECT_ID', '--non-interactive']
    
  • 权限配置:确保CloudBuild服务账号(格式通常为[你的项目编号]@cloudbuild.gserviceaccount.com)拥有Firebase Hosting Admin(roles/firebase.hostingAdmin)权限,避免因权限不足导致操作失败。

内容的提问来源于stack exchange,提问作者Atef Hares

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 06:17:12