En haut de la page, sélectionnez l'onglet 1re génération.
Cliquez sur Connecter un dépôt.
Sélectionnez Bitbucket Server.
Le panneau Connecter un dépôt s'affiche. Pour connecter votre dépôt Bitbucket Server, procédez comme suit :
Région : sélectionnez la région dans laquelle se trouve votre connexion.
Sous Sélectionner un fournisseur de gestion de code source, sélectionnez Bitbucket Server.
Connexion hôte : sélectionnez le nom de votre connexion hôte dans le menu déroulant.
Cliquez sur Continuer.
Sous Sélectionner un dépôt, sélectionnez les dépôts Bitbucket Server que vous souhaitez connecter à Cloud Build.
Une fois que vous avez sélectionné votre compte et vos dépôts Bitbucket Server, lisez la clause de non-responsabilité et cochez la case à côté de celle-ci pour indiquer que vous acceptez les conditions d'utilisation.
Cliquez sur Connecter pour connecter vos dépôts.
Lorsqu'un dépôt est connecté, Cloud Build configure un webhook sur le dépôt dans votre instance Bitbucket Server. Le dépôt envoie ensuite des webhooks pour appeler les déclencheurs Bitbucket Server correspondants lorsque vous apportez des modifications à votre dépôt. Un dépôt peut également être associé plusieurs fois à plusieurs connexions hôtes.
Pour savoir comment gérer les webhooks, consultez Gérer les webhooks.
Pour localiser le webhook, vous avez besoin de son ID. L'ID du webhook pour chaque dépôt connecté se trouve dans BitbucketServerConfig.
Saisissez la commande suivante pour récupérer l'ID du webhook :
PROJECT_NUMBER est le numéro de votre projet Cloud.
REGION correspond à la région associée à votre configuration Bitbucket Server.
BITBUCKET_SERVER_CONFIG_NAME est le nom de votre configuration Bitbucket Server.
PROJECT_KEY est la clé de votre projet Bitbucket Server.
Si vous souhaitez connecter un dépôt personnel, la clé de votre projet doit contenir le symbole tilde (~) avant votre nom d'utilisateur. Exemple : ~${USERNAME}. L'URL complète d'un dépôt hôte peut ressembler à https://${HOST_URI}/projects/~${USER_NAME}/repos/${REPO_SLUG}.
REPO_SLUG est le slug de votre dépôt Bitbucket Server.
Saisissez la commande curl suivante dans votre terminal :
PROJECT_NUMBER est le numéro de votre projet Cloud.
PROJECT_ID est votre ID de projet cloud.
REGION correspond à la région associée à votre configuration Bitbucket Server.
OPERATION_ID est l'ID de l'opération de création de la configuration Bitbucket Server.
Vous trouverez l'ID d'opération dans le champ name de votre réponse. Le format du champ name dans votre réponse ressemble à ce qui suit : projects/project-id/locations/region/operations/operation-id.
Vous devrez peut-être continuer à exécuter la commande d'API GetOperation jusqu'à ce que la réponse contienne done: true, ce qui indique que l'opération est terminée. Si le dépôt Bitbucket Server est correctement associé, vous pouvez le voir dans le champ response.bitbucketServerConnectedRepositories. Sinon, consultez le champ error pour obtenir un rapport d'erreur détaillé.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThis page details the process of connecting a Bitbucket Server repository to Cloud Build, allowing for automated builds upon code changes.\u003c/p\u003e\n"],["\u003cp\u003eBefore connecting, users must enable the Cloud Build, Secret Manager, and Compute Engine APIs, and also connect a Bitbucket Server host.\u003c/p\u003e\n"],["\u003cp\u003eConnecting a repository can be done through the Google Cloud console, where users must select their region, source code management provider, host connection, and specific repositories.\u003c/p\u003e\n"],["\u003cp\u003eAlternatively, users can connect a Bitbucket Server repository using the API, which involves using a JSON template and \u003ccode\u003ecurl\u003c/code\u003e commands to configure and verify the connection.\u003c/p\u003e\n"],["\u003cp\u003eOnce connected, Cloud Build configures a webhook on the repository, allowing it to send webhooks that invoke triggers when changes occur, and users can further manage webhooks to learn about troubleshooting them.\u003c/p\u003e\n"]]],[],null,["# Connect to a Bitbucket Server repository\n\nThis page explains how to connect to a [Bitbucket Server](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-repo-bitbucket-server)\n\n\u003c!-- --\u003e\n\n- Follow the instructions to [connect a Bitbucket Server host](/build/docs/automating-builds/bitbucket/connect-host-bitbucket-server) before connecting repositories.\n\nConnecting to a Bitbucket Server repository\n-------------------------------------------\n\n### Console\n\nTo connect a Bitbucket Server 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 Server**.\n\n You will see the **Connect Repository** panel. Complete the following\n steps to connect your Bitbucket Server repository:\n 1. **Region**: Select a region your connection is in.\n\n 2. Under **Select source code management provider** , select **Bitbucket Server**.\n\n 3. **Host connection**: Select the name of your host connection from the drop-down menu.\n\n 4. Click **Continue**.\n\n 5. Under **Select Repository**, select the Bitbucket Server repositories\n you wish to connect to Cloud Build.\n\n 6. Once you have selected your Bitbucket Server 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\n When a repository is connected, Cloud Build\n configures a webhook on the repository\n in your Bitbucket Server instance. The repository\n then sends webhooks to invoke the\n corresponding Bitbucket Server triggers when\n you make changes to your repository. A\n repository can also be connected multiple\n times with multiple host connections.\n To learn how to manage webhooks, see [Manage webhooks](https://confluence.atlassian.com/bitbucketserver/manage-webhooks-938025878.html#Managewebhooks-troubleshootingwebhooks).\n\n To locate the webhook, you need the webhook ID. The webhook ID\n for each connected repository can be found in the `BitbucketServerConfig`.\n\n Enter 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\n Where:\n - \u003cvar translate=\"no\"\u003eCONFIG_NAME\u003c/var\u003e is the name of the Bitbucket Server config\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e is the region of the Bitbucket Server host connection\n5. Click **Done** . Optionally, click **Create a trigger** to create a trigger.\n\n### API\n\nTo connect your Bitbucket Server repository to Cloud Build\nusing the API, complete the following steps:\n\n1. Use the following JSON template below to connect your repository:\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_SERVER_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_SERVER_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_SERVER_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 Server configuration.\n - \u003cvar translate=\"no\"\u003eBITBUCKET_SERVER_CONFIG_NAME\u003c/var\u003e is the name of your Bitbucket Server configuration.\n - \u003cvar translate=\"no\"\u003ePROJECT_KEY\u003c/var\u003e is the key of your Bitbucket Server 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 may look like `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 Server repository.\n2. Enter the following `curl` command in your terminal:\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\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePROJECT_ID\u003c/span\u003e\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eREGION\u003c/span\u003e\u003c/var\u003e/bitbucketServerConfigs/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eBITBUCKET_SERVER_CONFIG_NAME\u003c/span\u003e\u003c/var\u003e/connectedRepositories:batchCreate -d @requests.json\n\n Where:\n - \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e is your Cloud project number.\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e is your Cloud project ID.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e is the [region](/build/docs/locations) associated with your Bitbucket Server configuration.\n - \u003cvar translate=\"no\"\u003eBITBUCKET_SERVER_CONFIG_NAME\u003c/var\u003e is the name of your Bitbucket Server configuration.\n\n If successful, the response body contains a newly created instance of [Operation](https://cloud.google.com/build/docs/api/reference/rest/v1/operations#Operation).\n3. Enter 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 Cloud project number.\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e is your Cloud project ID.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e is the [region](/build/docs/locations) associated with your Bitbucket Server configuration.\n - \u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e is the ID of your Bitbucket Server 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 response contains `done: true`, which indicates the operation is completed. If the Bitbucket Server repository is connected successfully, you can see the connected repository in the `response.bitbucketServerConnectedRepositories` field. Otherwise, see the `error` field for a detailed error report.\n\nWhat's next\n-----------\n\n- Learn how to [build repositories from Bitbucket Server](/build/docs/automating-builds/bitbucket/build-repos-from-bitbucket-server).\n- Learn how to [build repositories from Bitbucket Server in a private network](/build/docs/automating-builds/bitbucket/build-repos-from-bitbucket-server-private-network).\n- Learn how to [perform blue/green deployments on Compute Engine](/build/docs/deploying-builds/deploy-compute-engine)."]]