Deployment berkelanjutan dari Git menggunakan Cloud Build
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Anda dapat menggunakan Cloud Build untuk mengotomatiskan build dan deployment ke Cloud Run dengan menggunakan pemicu Cloud Build untuk mem-build dan men-deploy kode secara otomatis setiap kali commit baru didorong ke cabang tertentu dari repositori Git. Sebagai contoh, lihat
panduan memulai untuk membuat repositori template dan men-deploy secara berkelanjutan dari
git.
Saat Anda menggunakan pemicu Cloud Build untuk membangun container, informasi repositori sumber akan ditampilkan di konsol Google Cloud untuk layanan Anda setelah Anda melakukan deployment ke Cloud Run.
Atau, Anda dapat menggunakan Cloud Deploy untuk menyiapkan pipeline continuous delivery guna men-deploy layanan Cloud Run ke beberapa lingkungan.
Sebelum memulai
Anda memiliki repositori git dengan Dockerfile atau codebase Anda ditulis dalam salah satu bahasa yang didukung oleh buildpack Google Cloud.
Untuk mendapatkan izin yang Anda perlukan untuk men-deploy layanan Cloud Run dari Git menggunakan Cloud Build,
minta administrator untuk memberi Anda
peran IAM berikut di project Anda:
Menyiapkan deployment berkelanjutan dari antarmuka pengguna Cloud Run
Prosedur penyiapan sedikit berbeda bergantung pada apakah Anda menyiapkan
deployment berkelanjutan pada layanan baru atau pada layanan yang sudah ada. Klik tab yang sesuai untuk mempelajari lebih lanjut.
Layanan baru
Buat layanan baru seperti yang dijelaskan dalam Men-deploy layanan baru,
pastikan Anda memilih Terus-menerus men-deploy revisi baru dari repositori sumber
di Service setelan.
Di halaman Service settings, klik Set up with Cloud Build.
GitHub adalah penyedia repositori default. Jika Anda belum
diautentikasi, klik Authenticate, lalu ikuti petunjuknya.
Repositori dihubungkan menggunakan aplikasi GitHub Cloud Build.
Klik Berikutnya.
Isi opsi pada langkah Konfigurasi Build:
Branch - menunjukkan sumber yang harus digunakan saat menjalankan
pemicu. Anda dapat memasukkan regex
di sini. Cabang yang cocok akan otomatis diverifikasi: Anda dapat
melihatnya di bawah input. Perhatikan bahwa jika hanya satu cabang yang cocok, pemicu akan otomatis dieksekusi setelah pembuatan.
Jenis Build
Jika repositori Anda harus di-build menggunakan Docker dan berisi Dockerfile, pilih Dockerfile. Source location menunjukkan lokasi dan nama Dockerfile. Direktori ini akan digunakan sebagai konteks build Docker. Semua jalur harus relatif terhadap direktori saat ini.
Jika tidak, pilih Google Cloud Buildpacks. Gunakan
Konteks Buildpack untuk menentukan direktori dan Entrypoint
(opsional) guna memberikan perintah untuk memulai server. Contoh:
gunicorn -p :8080 main:app untuk Python,
java -jar target/myjar.jar untuk Java. Biarkan kosong untuk menggunakan
perilaku default.
Klik Simpan.
Verifikasi setelan yang dipilih.
Klik Buat.
Perlu diperhatikan bahwa Anda akan dialihkan ke halaman Detail Layanan untuk melacak progres penyiapan Continuous Deployment.
Setelah semua langkah selesai, perhatikan opsi tambahan:
Temukan layanan dalam daftar layanan, lalu klik layanan tersebut.
Klik Set up Continuous Deployment.
GitHub adalah penyedia repositori default. Jika Anda belum
diautentikasi, klik Authenticate, lalu ikuti petunjuknya.
Repositori dihubungkan menggunakan aplikasi GitHub Cloud Build.
Klik Berikutnya.
Isi opsi pada langkah Konfigurasi Build:
Branch - menunjukkan sumber yang harus digunakan saat menjalankan
pemicu. Anda dapat memasukkan regex
di sini. Cabang yang cocok akan otomatis diverifikasi: Anda dapat
melihatnya di bawah input. Perhatikan bahwa jika hanya satu cabang yang cocok, pemicu akan otomatis dieksekusi setelah pembuatan.
Jenis Build
Jika repositori Anda harus di-build menggunakan Docker dan berisi Dockerfile, pilih Dockerfile. Source location menunjukkan lokasi dan nama Dockerfile. Direktori ini akan digunakan sebagai konteks build Docker. Semua jalur harus relatif terhadap direktori saat ini.
Jika tidak, pilih Google Cloud Buildpacks. Gunakan
Konteks Buildpack untuk menentukan direktori dan Entrypoint
(opsional) guna memberikan perintah untuk memulai server. Contoh:
gunicorn -p :8080 main:app untuk Python,
java -jar target/myjar.jar untuk Java. Biarkan kosong untuk menggunakan
perilaku default.
Klik Simpan.
Halaman akan dimuat ulang dan menampilkan progres penyiapan Continuous Deployment.
Setelah semua langkah selesai, perhatikan opsi tambahan:
Memasang pemicu Cloud Build yang ada untuk layanan Cloud Run
Jika sudah memiliki pemicu Cloud Build, Anda dapat melampirkannya ke layanan dan memanfaatkan fitur konsol di halaman Service Details: tombol Edit Continuous Deployment dan diagram Build History. Google Cloud
Untuk melakukannya, tambahkan label dengan gcb-trigger-id sebagai kunci dan ID unik pemicu Cloud Build sebagai nilai (bukan nama pemicu). Lihat Menetapkan atau mengubah label untuk menyiapkan label.
[[["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-21 UTC."],[],[],null,["# Continuous deployment from Git using Cloud Build\n\nYou can use Cloud Build to automate builds and deployments to\nCloud Run by using [Cloud Build trigger](/build/docs/running-builds/automate-builds)\nto automatically build and deploy your code whenever new commits are pushed to\na given branch of a Git repository. For an example, see the\nquickstart for [creating a template repository and deploying continuously from\ngit](/run/docs/quickstarts/deploy-continuously).\n\nWhen you use a Cloud Build trigger to build containers, the\n[source repository information is displayed](/run/docs/managing/revisions#build-source)\nin the Google Cloud console for your service after you deploy to\nCloud Run.\n\nAlternatively, you can use [Cloud Deploy](/deploy/docs/deploy-app-run) to set up a continuous-delivery\npipeline to deploy Cloud Run services to multiple environments.\n\nBefore you begin\n----------------\n\n- You either have a git repository with a `Dockerfile` or your codebase is written in one of the languages supported by [Google Cloud's buildpacks](/docs/buildpacks/builders).\n-\n\n\n Enable the Cloud Build\n API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com)\n\n### Required roles\n\n\nTo get the permissions that\nyou need to deploy Cloud Run services from Git using Cloud Build,\n\nask your administrator to grant you the\nfollowing IAM roles on your project:\n\n- [Artifact Registry Administrator](/iam/docs/roles-permissions/artifactregistry#artifactregistry.admin) (`roles/artifactregistry.admin`)\n- [Cloud Build Editor](/iam/docs/roles-permissions/cloudbuild#cloudbuild.builds.editor) (`roles/cloudbuild.builds.editor`)\n- [Cloud Run Developer](/iam/docs/roles-permissions/run#run.developer) (`roles/run.developer`)\n- [Service Account User](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`)\n- [Service Usage Admin](/iam/docs/roles-permissions/serviceusage#serviceusage.serviceUsageAdmin) (`roles/serviceusage.serviceUsageAdmin`)\n\n\nThe service account running the build must have the following roles:\n\n- [Cloud Build Service Account](/iam/docs/understanding-roles#cloudbuild.builds.builder) (`roles/cloudbuild.builds.builder`)\n- [Cloud Run Admin](/iam/docs/understanding-roles#run.admin) (`roles/run.admin`)\n- [Service Account User](/iam/docs/understanding-roles#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`)\n\nFor a list of IAM roles and permissions that are associated with\nCloud Run, see\n[Cloud Run IAM roles](/run/docs/reference/iam/roles)\nand [Cloud Run IAM permissions](/run/docs/reference/iam/permissions).\nIf your Cloud Run service interfaces with\nGoogle Cloud APIs, such as Cloud Client Libraries, see the\n[service identity configuration guide](/run/docs/configuring/services/service-identity).\nFor more information about granting roles, see\n[deployment permissions](/run/docs/reference/iam/roles#additional-configuration)\nand [manage access](/iam/docs/granting-changing-revoking-access).\n\nSet up continuous deployment from the Cloud Run user interface\n--------------------------------------------------------------\n\nThe setup procedure varies slightly depending on whether you are setting up\ncontinuous deployment on a new service or on an existing service. Click the\nappropriate tab to learn more. \n\n### New service\n\n1. Create a new service as described in [Deploy a new service](/run/docs/deploying#service),\n making sure you select **Continuously deploy new revisions from a source repository**\n in the *Service settings* page.\n\n2. In the *Service settings* page, click **Set up with Cloud Build**.\n\n3. GitHub is the default repository provider. If you are not yet\n authenticated, click **Authenticate** and follow the instructions.\n Connecting a repository is done using the Cloud Build GitHub app.\n\n4. Click **Next**.\n\n5. Fill the options in Build Configuration step:\n\n - *Branch* - indicates what source should be used when running the trigger. You can put the [regex](https://github.com/google/re2/wiki/Syntax) here. Matched branches are automatically verified: you can see them below the input. Note that if exactly one branch is matched, the trigger will be automatically executed after the creation.\n - *Build Type*\n\n - If your repository should be built using Docker and it contains a\n Dockerfile, select **Dockerfile** . **Source location** indicates the\n location and name of the Dockerfile. This directory will be used as the\n Docker build context. All paths should be relative to the current\n directory.\n\n - Otherwise, select **Google Cloud Buildpacks** . Use\n **Buildpack context** to specify the directory and **Entrypoint**\n (optional) to provide the command to start the server. Example:\n `gunicorn -p :8080 main:app` for Python,\n `java -jar target/myjar.jar` for Java. Leave it blank to use\n [default behavior](/docs/buildpacks/service-specific-configs#google_entrypoint).\n\n6. Click **Save**.\n\n7. Verify the selected settings.\n\n8. Click **Create**.\n\n9. Note that you are redirected to the *Service Details* page, where you can\n track the progress of your Continuous Deployment set up.\n\n10. Once all steps are completed, note additional options:\n\n - Edit Continuous Deployment.\n - Build History.\n - Source details in the [*Revision Details* section](/run/docs/managing/revisions#viewing_revision_details).\n\n### Existing service\n\n1. [Go to Cloud Run](https://console.cloud.google.com/run)\n\n2. Locate the service in the services list, and click it.\n\n3. Click **Set up Continuous Deployment**.\n\n4. GitHub is the default repository provider. If you are not yet\n authenticated, click **Authenticate** and follow the instructions.\n Connecting a repository is done using the Cloud Build GitHub app.\n\n5. Click **Next**.\n\n6. Fill the options in Build Configuration step:\n\n - *Branch* - indicates what source should be used when running the trigger. You can put the [regex](https://github.com/google/re2/wiki/Syntax) here. Matched branches are automatically verified: you can see them below the input. Note that if exactly one branch is matched, the trigger will be automatically executed after the creation.\n - *Build Type*\n\n - If your repository should be built using Docker and it contains a\n Dockerfile, select **Dockerfile** . **Source location** indicates the\n location and name of the Dockerfile. This directory will be used as the\n Docker build context. All paths should be relative to the current\n directory.\n\n - Otherwise, select **Google Cloud Buildpacks** . Use\n **Buildpack context** to specify the directory and **Entrypoint**\n (optional) to provide the command to start the server. Example:\n `gunicorn -p :8080 main:app` for Python,\n `java -jar target/myjar.jar` for Java. Leave it blank to use\n [default behavior](/docs/buildpacks/service-specific-configs#google_entrypoint).\n\n7. Click **Save**.\n\n8. The page reloads and displays the progress of the\n Continuous Deployment setup.\n\n9. Once all steps are completed, note additional options:\n\n - Edit Continuous Deployment.\n - Build History.\n - Source details in the [*Revision Details* section](/run/docs/managing/revisions#viewing_revision_details).\n\nSet up continuous deployment manually\n-------------------------------------\n\nRefer to [Setting up continuous deployment manually](/build/docs/deploying-builds/deploy-cloud-run) if you\nneed to use a manual procedure and not the UI.\n\nAttach existing Cloud Build trigger to Cloud Run service.\n---------------------------------------------------------\n\nIf you already have an existing Cloud Build trigger, you can attach it to\nthe service and take advantage of Google Cloud console features in the Service\nDetails page: *Edit Continuous Deployment* button and *Build History* chart.\n\nTo do this, add a label with \u003cvar translate=\"no\"\u003egcb-trigger-id\u003c/var\u003e as a key and\nthe unique identifier of the Cloud Build trigger as value (not the trigger\nname). See [Set or modify labels](/run/docs/configuring/services/labels#set-labels) for\nsetting up the label."]]