Untuk menjalankan perintah gcloud di halaman ini, instal
Google Cloud CLI.
Siapkan kode sumber aplikasi Anda, termasuk firebase.json. Kode sumber Anda harus disimpan dalam repositori, seperti Cloud Source Repositories, GitHub, atau Bitbucket.
Di tabel izin, temukan email untuk akun layanan yang Anda gunakan untuk build, lalu klik ikon pensil.
Tambahkan peran Cloud Build Service Account(roles/cloudbuild.builds.builder),
Firebase Admin (roles/firebase.admin), danAPI Keys Admin
(roles/serviceusage.apiKeysAdmin)
ke akun layanan.
Klik Simpan.
Menggunakan image Docker firebase
Cloud Build menyediakan image builder yang dapat Anda gunakan untuk memanggil perintah
firebase di Cloud Build. Untuk menggunakan builder ini dalam file konfigurasi Cloud Build, Anda dapat menggunakan langkah build firebase untuk men-deploy ke Firebase:
Buat file konfigurasi build bernama cloudbuild.yaml atau
cloudbuild.json dengan PROJECT_ID sebagai
Google Cloud project ID dan FIREBASE_PROJECT_ID sebagai
project ID Firebase Anda:
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 adalah jalur ke file konfigurasi build.
SOURCE_DIRECTORY adalah jalur atau URL ke kode sumber.
Deployment berkelanjutan
Anda dapat mengotomatiskan deployment software ke Firebase dengan membuat pemicu Cloud Build. Anda dapat mengonfigurasi pemicu untuk mem-build
dan men-deploy image setiap kali Anda memperbarui kode sumber.
Untuk mengotomatiskan deployment ke Firebase:
Di repositori Anda, tambahkan file konfigurasi build dengan langkah-langkah untuk memanggil perintah
firebase deploy dengan PROJECT_ID
adalah project ID Google Cloud Anda:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 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,["# Deploying to Firebase\n\nThis 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\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\n### Required 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---------------------------------\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---------------------\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------------\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\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)"]]