You can configure your Bitbucket repository to automatically build and deploy an environment when you push code changes. This integration synchronizes your Bitbucket repository with your Adobe Commerce on cloud infrastructure account.
We strongly recommend using a private repository for your Adobe Commerce on cloud infrastructure project to protect any proprietary information or development work, such as extensions and sensitive configurations.
magento-cloud
CLI tool in your local environmentClone your Adobe Commerce on cloud infrastructure project from an existing environment and migrate the project branches to a new, empty Bitbucket repository, preserving the same branch names. It is critical to retain an identical Git tree, so that you do not lose any existing environments or branches in your Adobe Commerce on cloud infrastructure project.
From the terminal, log in to your Adobe Commerce on cloud infrastructure project.
magento-cloud login
List your projects and copy the project ID.
magento-cloud project:list
Clone the project to your local environment.
magento-cloud project:get <project-ID>
Add your Bitbucket repository as a remote.
git remote add origin git@bitbucket.org:<user-name>/<repo-name>.git
The default name for the remote connection may be origin
or magento
. If origin
exists, you can choose a different name or you can rename or delete the existing reference. See git-remote documentation.
Verify that you added the Bitbucket remote correctly.
git remote -v
Expected response:
origin git@bitbucket.org:<user-name>/<repo-name>.git (fetch)
origin git@bitbucket.org:<user-name>/<repo-name>.git (push)
Push the project files to your new Bitbucket repository. Remember to keep all branch names the same.
git push -u origin master
If you are starting with a new Bitbucket repository, you may have to use the -f
option, because the remote repository does not match your local copy.
Verify that your Bitbucket repository contains all of your project files.
The Bitbucket integration requires an OAuth consumer. You need the OAuth key
and secret
from this consumer to complete the next section.
To create an OAuth consumer in Bitbucket:
Log in to your Bitbucket account.
Click Settings > Access Management > OAuth.
Click Add consumer and configure it as follows:
A valid Callback URL is not required, but you must enter a value in this field to successfully complete the integration.
Click Save.
Click the consumer Name to reveal your OAuth key
and secret
.
Copy your OAuth key
and secret
for configuring the integration.
From the terminal, navigate to your Adobe Commerce on cloud infrastructure project.
Create a temporary file called bitbucket.json
and add the following, replacing the variables in angle brackets with your values:
{
"type": "bitbucket",
"repository": "<bitbucket-user-name/bitbucket-repo-name>",
"app_credentials": {
"key": "<oauth-consumer-key>",
"secret": "<oauth-consumer-secret>"
},
"prune_branches": true,
"fetch_branches": true,
"build_pull_requests": true,
"resync_pull_requests": true
}
Be sure to use the name of your Bitbucket repository and not the URL. The integration fails if you use a URL.
Add the integration to your project using the magento-cloud
CLI tool.
The following command overwrites all code in your Adobe Commerce on cloud infrastructure project with code from your Bitbucket repository. This includes all branches, including the production
branch. This action happens instantly and cannot be undone. As a best practice, it is important to clone all of your branches from your Adobe Commerce on cloud infrastructure project and push them to your Bitbucket repository before adding the Bitbucket integration.
magento-cloud project:curl -p '<project-ID>' /integrations -i -X POST -d "$(< bitbucket.json)"
This returns a long HTTP response with headers. A successful integration returns a 200 or 201 status code. A status of 400 or above indicates that an error occurred.
Delete the temporary bitbucket.json
file.
Verify the project integration.
magento-cloud integrations -p <project-ID>
+----------+-----------+--------------------------------------------------------------------------------+
| ID | Type | Summary |
+----------+-----------+--------------------------------------------------------------------------------+
| <int-id> | bitbucket | Repository: bitbucket_Account/magento-int |
| | | Hook URL: |
| | | https://magento-url.cloud/api/projects/<project-id>/integrations/<int-id>/hook |
+----------+-----------+--------------------------------------------------------------------------------+
Make a note of the Hook URL to configure a webhook in BitBucket.
In order to communicate events—such as a push—with your Cloud Git server, is it necessary to have a webhook for your BitBucket repository. The method of setting up a Bitbucket integration detailed on this page, when followed correctly, automatically creates a webhook. It is important to verify the webhook to avoid creating multiple integrations.
Log in to your Bitbucket account.
Click Repositories and select your project.
Click Repository Settings > Workflow > Webhooks.
Verify the webhook before continuing.
If the hook is active, skip the remaining steps and Test the integration. The hook should have a name similar to “Adobe Commerce on cloud infrastructure <project_id>” and a hook URL format similar to: https://<zone>.magento.cloud/api/projects/<project_id>/integrations/<id>/hook
Click Add webhook.
In the Add new webhook view, edit the following fields:
magento-cloud
integration listClick Save.
After configuring the Bitbucket integration, you can verify that the integration is operational using the magento-cloud
CLI:
magento-cloud integration:validate
Or you can test it by pushing a simple change to your Bitbucket repository.
Create a test file.
touch test.md
Commit and push the change to your Bitbucket repository.
git add . && git commit -m "Testing Bitbucket integration" && git push
Log in to the Project Web Interface and verify that your commit message is displayed and your project deploying.
The Bitbucket integration cannot activate new environments in your Adobe Commerce on cloud infrastructure project. If you create an environment with Bitbucket, you must activate the environment manually. To avoid this extra step, it is best practice to create environments using the magento-cloud
CLI tool or the Project Web Interface.
To activate a branch created with Bitbucket:
Use the magento-cloud
CLI to push the branch.
magento-cloud environment:push from-bitbucket
Pushing from-bitbucket to the new environment from-bitbucket
Activate from-bitbucket after pushing? [Y/n] y
Parent environment [master]: integration
--- (Validation and activation messages)
Verify that the environment is active.
magento-cloud environment:list
Your environments are:
+---------------------+----------------+--------+
| ID | Name | Status |
+---------------------+----------------+--------+
| master | Master | Active |
| integration | integration | Active |
| from-bitbucket * | from-bitbucket | Active |
+---------------------+----------------+--------+
* - Indicates the current environment
After you create an environment, you can push the corresponding branch to your remote Bitbucket repository using regular Git commands. Subsequent changes to your branch in Bitbucket automatically build and deploy the environment.
You can safely remove the Bitbucket integration from your project without affecting your code.
To remove the Bitbucket integration:
From the terminal, log in to your Adobe Commerce on cloud infrastructure project.
List your integrations. You need the Bitbucket integration ID to complete the next step.
magento-cloud integration:list
Delete the integration.
magento-cloud integration:delete <int-ID>
Also, you can remove the Bitbucket integration by logging in to your Bitbucket account and revoking the OAuth grant on the account Settings page.
To use the Bitbucket server integration, you need the following:
read
access and Repository admin
accessThough you can use the Cloud CLI to walk through the Bitbucket server integration steps, the full command looks similar to the following:
magento-cloud integration:add --type=bitbucket_server --base-url=<bitbucket-url> --username=<username> --token=<bitbucket-access-token> --project=<project-ID>
Use the help command for more usage requirements and options: magento-cloud integration:add --help