Per eseguire i comandi gcloud in questa pagina, installa
Google Cloud CLI.
Tieni a portata di mano il codice sorgente dell'applicazione, incluso firebase.json. Il codice sorgente deve essere archiviato in un repository, ad esempio Cloud Source Repositories, GitHub o Bitbucket.
Nella tabella delle autorizzazioni, individua l'email dell'account di servizio che stai
utilizzando per la build e fai clic sull'icona a forma di matita.
Aggiungi i ruoli Cloud Build Service Account(roles/cloudbuild.builds.builder),
Firebase Admin (roles/firebase.admin) eAPI Keys Admin
(roles/serviceusage.apiKeysAdmin)
al account di servizio.
Fai clic su Salva.
Utilizzo dell'immagine Docker firebase
Cloud Build fornisce un'immagine builder che puoi utilizzare per richiamare i comandi firebase in Cloud Build. Per utilizzare questo builder in un file di configurazione di Cloud Build, puoi utilizzare il passaggio di build firebase per eseguire il deployment su Firebase:
Crea un file di configurazione della build denominato cloudbuild.yaml o
cloudbuild.json, dove PROJECT_ID è il tuo
Google Cloud ID progetto e FIREBASE_PROJECT_ID è
il tuo ID progetto 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 è il percorso del file di configurazione della build.
SOURCE_DIRECTORY è il percorso o l'URL del codice sorgente.
Deployment continuo
Puoi automatizzare il deployment del tuo software su Firebase creando trigger di Cloud Build. Puoi configurare i trigger per creare
ed eseguire il deployment delle immagini ogni volta che aggiorni il codice sorgente.
Per automatizzare il deployment in Firebase:
Nel repository, aggiungi un file di configurazione della build con i passaggi per richiamare il comando firebase deploy, dove PROJECT_ID è il tuo ID progetto Google Cloud :
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)"]]