Anda akan melihat panel Connect Repository. Selesaikan langkah-langkah berikut untuk menghubungkan repositori Bitbucket Data Center Anda:
Region: Pilih region tempat koneksi Anda berada.
Di bagian Pilih penyedia pengelolaan kode sumber, pilih Bitbucket
Data Center.
Host connection: Pilih nama koneksi host Anda dari
menu drop-down.
Klik Lanjutkan.
Di bagian Select Repository, pilih repositori Pusat Data Bitbucket
yang ingin Anda hubungkan ke Cloud Build.
Setelah Anda memilih akun dan repositori Bitbucket Data Center, baca pernyataan penyangkalan izin dan centang kotak di sampingnya untuk menunjukkan bahwa Anda menyetujui persyaratan yang ditampilkan.
Klik Connect untuk menghubungkan repositori Anda.
Klik Selesai. Atau, klik Buat pemicu untuk membuat pemicu.
API
Untuk menghubungkan repositori Bitbucket Data Center ke Cloud Build menggunakan API, selesaikan langkah-langkah berikut:
REGION adalah wilayah
yang terkait dengan konfigurasi Pusat Data Bitbucket Anda.
BITBUCKET_DATA_CENTER_CONFIG_NAME adalah nama konfigurasi Bitbucket Data Center Anda.
PROJECT_KEY adalah kunci project Bitbucket Data Center Anda. Jika Anda ingin menghubungkan repositori pribadi, kunci project Anda harus berisi simbol tilde (~) sebelum nama pengguna Anda. Contohnya,
~${USERNAME}. URL lengkap untuk repositori host mirip dengan https://${HOST_URI}/projects/~${USER_NAME}/repos/${REPO_SLUG}.
REPO_SLUG adalah
slug
repositori Bitbucket Data Center Anda.
Jalankan perintah curl berikut di terminal Anda dari direktori yang sama dengan file JSON:
REGION adalah wilayah
yang terkait dengan konfigurasi Pusat Data Bitbucket Anda.
BITBUCKET_DATA_CENTER_CONFIG_NAME adalah nama konfigurasi Bitbucket Data Center Anda.
Jika berhasil, isi respons akan memuat instance Operation yang baru dibuat.
PROJECT_NUMBER adalah nomor project Google Cloud Anda.
PROJECT_ID adalah Google Cloud ID Anda.
REGION adalah wilayah
yang terkait dengan konfigurasi Pusat Data Bitbucket Anda.
OPERATION_ID adalah ID operasi pembuatan konfigurasi Bitbucket Data Center Anda. Anda dapat menemukan ID Operasi
di kolom name respons Anda. Format kolom name dalam
respons Anda akan terlihat seperti berikut:
projects/project-id/locations/region/operations/operation-id.
Anda mungkin perlu terus menjalankan perintah API GetOperation hingga
respons berisi done: true, yang menunjukkan bahwa operasi telah
selesai. Jika repositori Pusat Data Bitbucket berhasil terhubung, Anda dapat melihat repositori yang terhubung di kolom response.bitbucketServerConnectedRepositories. Jika tidak, lihat kolom
error untuk laporan error mendetail.
Saat repositori terhubung, Cloud Build akan mengonfigurasi webhook di repositori dalam instance Pusat Data Bitbucket Anda. Kemudian, repositori akan mengirim webhook untuk memanggil pemicu Pusat Data Bitbucket yang sesuai saat Anda membuat perubahan pada repositori. Repositori juga dapat dihubungkan beberapa kali dengan beberapa koneksi host. Untuk mempelajari cara mengelola webhook, lihat Mengelola webhook.
Untuk menemukan webhook, Anda memerlukan ID webhook. ID webhook untuk setiap repositori yang terhubung dapat ditemukan di BitbucketServerConfig.
Masukkan perintah berikut untuk mengambil ID webhook:
[[["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-09-04 UTC."],[[["\u003cp\u003eThis guide outlines the process of connecting a Bitbucket Data Center repository to Cloud Build for automated builds.\u003c/p\u003e\n"],["\u003cp\u003eBefore connecting, you need to enable the Cloud Build, Secret Manager, and Compute Engine APIs and follow instructions to connect a Bitbucket Data Center host.\u003c/p\u003e\n"],["\u003cp\u003eYou can connect using the Google Cloud console by selecting Bitbucket Data Center, your host connection, and then specific repositories.\u003c/p\u003e\n"],["\u003cp\u003eThe API method involves creating a JSON file with specific details, and using \u003ccode\u003ecurl\u003c/code\u003e commands to connect the repository and verify the connection.\u003c/p\u003e\n"],["\u003cp\u003eOnce connected, Cloud Build sets up a webhook in your Bitbucket Data Center instance, and the webhook ID can be retrieved using the \u003ccode\u003egcloud\u003c/code\u003e command.\u003c/p\u003e\n"]]],[],null,["# Connect to a Bitbucket Data Center repository\n\n1st gen 2nd gen\n\nThis page explains how to connect to a [Bitbucket Data Center](https://confluence.atlassian.com/bitbucketserver/bitbucket-data-center-and-server-documentation-776639749.html) repository\nto Cloud Build.\n\nBefore you begin\n----------------\n\n-\n\n\n Enable the Cloud Build, Secret Manager, and Compute Engine APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com,secretmanager.googleapis.com,compute.googleapis.com&redirect=https://cloud.google.com/build/docs/automating-builds/bitbucket/connect-host-bitbucket-data-center)\n\n\u003c!-- --\u003e\n\n- Follow the instructions to [connect a Bitbucket Data Center host](/build/docs/automating-builds/bitbucket/connect-host-bitbucket-data-center) before connecting to a repository.\n\nConnect to a Bitbucket Data Center repository\n---------------------------------------------\n\n### Console\n\nTo connect a Bitbucket Data Center repository to Cloud Build\nusing the Google Cloud console:\n\n1. Open the **Repositories** page in the Google Cloud console.\n\n [Open the Repositories page](https://console.cloud.google.com/cloud-build/repositories)\n2. At the top of the page, select the **1st gen** tab.\n\n3. Click **Connect Repository**.\n\n4. Select **Bitbucket Data Center**.\n\n You will see the **Connect Repository** panel. Complete the following\n steps to connect your Bitbucket Data Center repository:\n 1. **Region**: Select the region your connection is in.\n\n 2. Under **Select source code management provider** , select **Bitbucket\n Data Center**.\n\n 3. **Host connection**: Select the name of your host connection from the\n drop-down menu.\n\n 4. Click **Continue**.\n\n 5. Under **Select Repository**, select the Bitbucket Data Center repositories\n you want to connect to Cloud Build.\n\n 6. Once you have selected your Bitbucket Data Center account and repositories,\n read the consent disclaimer and select the checkbox next to it to indicate\n that you accept the presented terms.\n\n 7. Click **Connect** to connect your repositories.\n\n5. Click **Done** . Optionally, click **Create a trigger** to create a trigger.\n\n### API\n\nTo connect your Bitbucket Data Center repository to Cloud Build\nusing the API, complete the following steps:\n\n1. Create a JSON file with the following contents:\n\n {\n \"parent\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e/bitbucketServerConfigs/\u003cvar translate=\"no\"\u003eBITBUCKET_DATA_CENTER_CONFIG_NAME\u003c/var\u003e\",\n \"requests\": {\n \"parent\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e/bitbucketServerConfigs/\u003cvar translate=\"no\"\u003eBITBUCKET_DATA_CENTER_CONFIG_NAME\u003c/var\u003e\",\n \"bitbucketServerConnectedRepository\": {\n \"parent\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e/bitbucketServerConfigs/\u003cvar translate=\"no\"\u003eBITBUCKET_DATA_CENTER_CONFIG_NAME\u003c/var\u003e\",\n \"repo\": {\n \"projectKey\":\"\u003cvar translate=\"no\"\u003ePROJECT_KEY\u003c/var\u003e\",\n \"repoSlug\": \"\u003cvar translate=\"no\"\u003eREPO_SLUG\u003c/var\u003e\",\n }\n }\n }\n }\n\n Where:\n - \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e is the project number of your Cloud project.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e is the [region](/build/docs/locations) associated with your Bitbucket Data Center configuration.\n - \u003cvar translate=\"no\"\u003eBITBUCKET_DATA_CENTER_CONFIG_NAME\u003c/var\u003e is the name of your Bitbucket Data Center configuration.\n - \u003cvar translate=\"no\"\u003ePROJECT_KEY\u003c/var\u003e is the key of your Bitbucket Data Center project. If you want to connect a personal repository, your project key should contain the tilde (`~`) symbol before your username. For example, `~${USERNAME}`. The complete URL for a host repository is similar to `https://${HOST_URI}/projects/~${USER_NAME}/repos/${REPO_SLUG}`.\n - \u003cvar translate=\"no\"\u003eREPO_SLUG\u003c/var\u003e is the [slug](https://support.atlassian.com/bitbucket-cloud/docs/what-is-a-slug/) of your Bitbucket Data Center repository.\n2. Run the following `curl` command in your terminal from the same directory\n as the JSON file:\n\n curl -X POST -H \"Authorization: Bearer \"$(gcloud auth print-access-token) -H \"Content-Type: application/json; charset=utf-8\" -H \"x-goog-user-project: \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e\" https://cloudbuild.googleapis.com/v1/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e/bitbucketServerConfigs/\u003cvar translate=\"no\"\u003eBITBUCKET_DATA_CENTER_CONFIG_NAME\u003c/var\u003e/connectedRepositories:batchCreate -d @requests.json\n\nWhere:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e is your Google Cloud project number.\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e is your Google Cloud [project ID](/resource-manager/docs/creating-managing-projects#get_an_existing_project).\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e is the [region](/build/docs/locations) associated with your Bitbucket Data Center configuration.\n- \u003cvar translate=\"no\"\u003eBITBUCKET_DATA_CENTER_CONFIG_NAME\u003c/var\u003e is the name of your Bitbucket Data Center configuration. If successful, the response body contains a newly created instance of [Operation](/build/docs/api/reference/rest/v1/operations#Operation).\n\n1. Run the following `curl` command in your terminal:\n\n curl -X GET -H \"Authorization: Bearer \"$(gcloud auth print-access-token) -H \"Content-Type: application/json; charset=utf-8\" -H \"x-goog-user-project: \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e\" https://cloudbuild.googleapis.com/v1/projects/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nt\"\u003ePROJECT_ID\u003c/span\u003e\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nt\"\u003eREGION\u003c/span\u003e\u003c/var\u003e/operations/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nt\"\u003eOPERATION_ID\u003c/span\u003e\u003c/var\u003e\n\n Where:\n - \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e is your Google Cloud project number.\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e is your Google Cloud ID.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e is the [region](/build/docs/locations) associated with your Bitbucket Data Center configuration.\n - \u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e is the ID of your Bitbucket Data Center configuration creation operation. You can find the Operation ID in the `name` field of your response. The format of the `name` field in your response looks like the following: `projects/project-id/locations/region/operations/operation-id`.\n\n You may need to keep running the `GetOperation` API command until the\n response contains `done: true`, which indicates the operation is\n completed. If the Bitbucket Data Center repository is connected\n successfully, you can see the connected repository in the\n `response.bitbucketServerConnectedRepositories` field. Otherwise, see the\n `error` field for a detailed error report.\n\nWhen a repository is connected, Cloud Build configures a webhook on\nthe repository in your Bitbucket Data Center instance. The repository then\nsends webhooks to invoke the corresponding Bitbucket Data Center triggers when\nyou make changes to your repository. A repository can also be connected\nmultiple times with multiple host connections. To learn how to manage\nwebhooks, see\n[Manage webhooks](https://confluence.atlassian.com/bitbucketserver/manage-webhooks-938025878.html#Managewebhooks-troubleshootingwebhooks).\n\nTo locate the webhook, you need the webhook ID. The webhook ID for each\nconnected repository can be found in the `BitbucketServerConfig`.\n\nEnter the following command to retrieve the webhook ID: \n\n gcloud alpha builds enterprise-config bitbucketserver describe \u003cvar translate=\"no\"\u003eCONFIG_NAME\u003c/var\u003e --region=\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e\n\nWhere:\n\n- \u003cvar translate=\"no\"\u003eCONFIG_NAME\u003c/var\u003e is the name of the Bitbucket Data Center config\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e is the region of the Bitbucket Data Center host connection\n\nWhat's next\n-----------\n\n- Learn how to [build repositories from Bitbucket Data Center](/build/docs/automating-builds/bitbucket/build-repos-from-bitbucket-data-center).\n- Learn how to [build repositories from Bitbucket Data Center in a private network](/build/docs/automating-builds/bitbucket/build-repos-from-bitbucket-data-center-private-network).\n- Learn how to [perform blue/green deployments on Compute Engine](/build/docs/deploying-builds/deploy-compute-engine)."]]