Para executar os comandos gcloud nesta página, instale a
Google Cloud CLI.
Mantenha o código-fonte do seu aplicativo, incluindo firebase.json, à mão. Seu código-fonte precisa ser armazenado em um repositório, como o Cloud Source Repositories, o GitHub ou o Bitbucket.
Na tabela de permissões, localize o e-mail da conta de serviço que você está
usando para o build e clique no ícone de lápis.
Adicione os papéis Cloud Build Service Account(roles/cloudbuild.builds.builder),
Firebase Admin (roles/firebase.admin) eAPI Keys Admin
(roles/serviceusage.apiKeysAdmin)
à conta de serviço.
Clique em Salvar.
Usar a imagem do Docker firebase
O Cloud Build fornece uma imagem de builder que pode ser usada para invocar
comandos firebase no Cloud Build. Para usar esse builder em um
arquivo de configuração do Cloud Build, use a etapa de build firebase para
implantar no Firebase:
Crie um arquivo de configuração de build chamado cloudbuild.yaml ou cloudbuild.json, em que PROJECT_ID é o ID do projeto doGoogle Cloud e FIREBASE_PROJECT_ID é o ID do projeto do Firebase:
YAML
steps:-name:"us-docker.pkg.dev/firebase-cli/us/firebase"args:['deploy','--project=FIREBASE_PROJECT_ID','--only=hosting']## Or, target a specific version of firebase-tools-name:"us-docker.pkg.dev/firebase-cli/us/firebase":x.y.zargs:['deploy','--project=FIREBASE_PROJECT_ID','--only=hosting']
CONFIG_FILE_PATH é o caminho para o arquivo de configuração da compilação;
SOURCE_DIRECTORY é o caminho ou o URL do código-fonte.
Implantação contínua
É possível automatizar a implantação do software no Firebase criando gatilhos do Cloud Build. É possível configurar acionadores para criar e implantar imagens sempre que você atualizar o código-fonte.
Para automatizar sua implantação no Firebase:
No repositório, adicione um arquivo de configuração de build com etapas para invocar o comando
firebase deploy, em que PROJECT_ID
é o ID do projeto Google Cloud :
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[[["\u003cp\u003eThis page provides instructions on deploying applications to Firebase using Cloud Build, assuming familiarity with Cloud Build's quickstarts and build configuration.\u003c/p\u003e\n"],["\u003cp\u003eBefore deploying, you must enable the Cloud Build, Firebase, and Resource Manager APIs, and have your application source code, including \u003ccode\u003efirebase.json\u003c/code\u003e, stored in a repository.\u003c/p\u003e\n"],["\u003cp\u003eTo deploy, you need to use the Firebase community builder image, which involves building and pushing it to the Container Registry or Artifact Registry.\u003c/p\u003e\n"],["\u003cp\u003eDeployment is configured via a build config file (\u003ccode\u003ecloudbuild.yaml\u003c/code\u003e or \u003ccode\u003ecloudbuild.json\u003c/code\u003e) specifying the Firebase project and deployment details.\u003c/p\u003e\n"],["\u003cp\u003eYou can set up continuous deployment to Firebase by creating Cloud Build triggers that automatically deploy updates whenever changes are pushed to the connected repository.\u003c/p\u003e\n"]]],[],null,["This page explains how to deploy applications to\n[Firebase](https://firebase.google.com/) using\nCloud Build. If you're new to Cloud Build, read the\n[quickstarts](/build/docs/quickstarts) and the\n[Build configuration overview](/build/docs/build-config) first.\n\nBefore you begin\n\n-\n\n\n Enable the Cloud Build, Firebase, and Resource Manager APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com,firebase.googleapis.com,firebasehosting.googleapis.com,cloudresourcemanager.googleapis.com&redirect=https://cloud.google.com/build/docs/deploying-builds/deploy-firebase)\n\n\u003c!-- --\u003e\n\n- To run the `gcloud` commands on this page, install the\n [Google Cloud CLI](/sdk).\n\n- Keep your application source code including `firebase.json` handy. Your\n source code needs to be stored in a repository, such as\n Cloud Source Repositories, GitHub, or Bitbucket.\n\n- If you don't already have a project to deploy to Firebase, you can\n create a default project by\n [installing and initializing Firebase](https://firebase.google.com/docs/hosting/quickstart#initialize).\n\n| **Caution:** Effective June 17, 2024, Cloud Source Repositories isn't available\n| to new customers. If your organization hasn't\n| previously used Cloud Source Repositories, you can't enable the API or use\n| Cloud Source Repositories. New projects not connected to an organization can't enable the\n| Cloud Source Repositories API. Organizations that have used Cloud Source Repositories prior to\n| June 17, 2024 are not affected by this change.\n\nRequired IAM permissions\n\n1. Open the IAM page in the Google Cloud console:\n\n [Open the IAM page](https://console.cloud.google.com/iam-admin/iam)\n2. Select your project and click **Open**.\n\n3. In the permissions table, locate the email for the service account you are\n using for the build and click the pencil icon.\n\n4. Add the `Cloud Build Service Account`(`roles/cloudbuild.builds.builder`),\n `Firebase Admin` (`roles/firebase.admin`), and`API Keys Admin`\n (`roles/serviceusage.apiKeysAdmin`)\n roles to the service account.\n\n5. Click **Save**.\n\nUsing the `firebase` Docker image\n\nCloud Build provides a builder image that you can use to invoke\n`firebase` commands in Cloud Build. To use this builder in a\nCloud Build config file, you can use the `firebase` build step to\ndeploy to Firebase:\n\n1. Create a build config file named `cloudbuild.yaml` or\n `cloudbuild.json` where \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e is your\n Google Cloud project ID and \u003cvar translate=\"no\"\u003eFIREBASE_PROJECT_ID\u003c/var\u003e is\n your Firebase project ID:\n\n YAML \n\n steps:\n - name: \"us-docker.pkg.dev/firebase-cli/us/firebase\"\n args: ['deploy', '--project=\u003cvar translate=\"no\"\u003eFIREBASE_PROJECT_ID\u003c/var\u003e', '--only=hosting']\n ## Or, target a specific version of firebase-tools\n - name: \"us-docker.pkg.dev/firebase-cli/us/firebase\":\u003cvar translate=\"no\"\u003ex.y.z\u003c/var\u003e\n args: ['deploy', '--project=\u003cvar translate=\"no\"\u003eFIREBASE_PROJECT_ID\u003c/var\u003e', '--only=hosting']\n\n JSON \n\n {\n \"steps\": [\n {\n \"name\": \"us-docker.pkg.dev/firebase-cli/us/firebase\",\n \"args\": [\n \"deploy\",\n \"--project\",\n \"\u003cvar translate=\"no\"\u003eFIREBASE_PROJECT_ID\u003c/var\u003e\",\n \"--only\",\n \"hosting\"\n ]\n }\n ]\n }\n\n You can choose a specific version of `firebase-tools` by using \n\n `name: \"us-docker.pkg.dev/firebase-cli/us/firebase\":`\u003cvar translate=\"no\"\u003ex.y.z\u003c/var\u003e\n2. Start the build using the build config file:\n\n gcloud builds submit --region=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eREGION\u003c/span\u003e\u003c/var\u003e --config \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eCONFIG_FILE_PATH\u003c/span\u003e\u003c/var\u003e \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSOURCE_DIRECTORY\u003c/span\u003e\u003c/var\u003e\n\n Where:\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e is one of the [supported build regions](/build/docs/locations).\n - \u003cvar translate=\"no\"\u003eCONFIG_FILE_PATH\u003c/var\u003e is the path to the build config file.\n - \u003cvar translate=\"no\"\u003eSOURCE_DIRECTORY\u003c/var\u003e is the path or URL to the source code.\n\nContinuous deployment\n\nYou can automate the deployment of your software to Firebase by\ncreating Cloud Build triggers. You can configure triggers to build\nand deploy images whenever you update your source code.\n\nTo automate your deployment to Firebase:\n\n1. In your repository, add a build config file with steps to invoke the\n `firebase deploy` command where \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\n is your Google Cloud project ID:\n\n YAML \n\n steps:\n - name: us-docker.pkg.dev/firebase-cli/us/firebase\n args: ['deploy', '--project=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e', '--only=hosting']\n\n JSON \n\n {\n \"steps\": [\n {\n \"name\": \"us-docker.pkg.dev/firebase-cli/us/firebase\",\n \"args\": [\n \"deploy\",\n \"--project\",\n \"\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\",\n \"--only\",\n \"hosting\"\n ]\n }\n ]\n }\n\n2. Create a trigger with the build config file created in the previous step:\n\n 1. Open the **Triggers** page in the Google Cloud console:\n\n [Open Triggers page](https://console.cloud.google.com/cloud-build/triggers)\n 2. Select your project from the project selector drop-down menu at the top of\n the page.\n\n 3. Click **Open**.\n\n 4. Click **Create trigger**.\n\n On the **Create trigger** page, enter the following settings:\n 1. Enter a name for your trigger.\n\n 2. Select the repository event to start your trigger.\n\n 3. Select the repository that contains your source code and build\n config file.\n\n 4. Specify the regex for the branch or tag name that will start your\n trigger.\n\n 5. **Configuration**: Choose the build config file you created\n previously.\n\n 5. Click **Create** to save your build trigger.\n\nAnytime you push new code to your repository, you will automatically start a\nbuild and deploy on Firebase.\n\nFor more information on creating Cloud Build triggers, see\n[Creating and managing build triggers](/build/docs/automating-builds/create-manage-triggers).\n\nCode example\n\nTo view a code sample for deploying to Firebase using Cloud Build, go to\n[deploy-firebase-example](https://github.com/GoogleCloudPlatform/cloud-build-samples/tree/main/deploy-firebase-example).\n\nWhat's next\n\n- Learn how to [perform blue/green deployments on Compute Engine](/build/docs/deploying-builds/deploy-compute-engine)\n- Learn how to [deploy on Cloud Run](/build/docs/deploying-builds/deploy-cloud-run)\n- Learn how to [deploy on GKE](/build/docs/deploying-builds/deploy-gke)\n- Learn how to [deploy on Cloud Run functions](/build/docs/deploying-builds/deploy-functions)\n- Learn how to [deploy on App Engine](/build/docs/deploying-builds/deploy-appengine)\n- Learn how to [troubleshoot build errors](/build/docs/troubleshooting)"]]