First of all, you don't need to integrate Bitbucket Pipelines as you do with your own host provider.
You can use the native integration between Magento Cloud and Github, Bitbucket, or Gitlab.
How to setup
This process is a lit bit long to write all so I'm sharing the main steps to you to follow a to-do list, all the process detailed is here in Devdocs. Before starting, make sure you have access to manage the project and manage the Bitbucket account, then install Magento Cloud CLI.
1 - Setup local
You need to do the login using the CLI, get the project using the CLI yet, then add the remote origin of your GIT repo.
2 - Create an OAuth consumer
Open your Bitbucket's account configuration and set a new OAuth consumer to be able to connect using a public and private key. Create a temporary file called bitbucket.json
like this below. Run the command to connect your Bitbucket with Magento Cloud and remove the file.
{
"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
}
And run:
magento-cloud project:curl -p '<project-ID>' /integrations -i -X POST -d "$(< bitbucket.json)"
When it's finished, run this command below to verify the integration and remove the temporary bitbucket.json
file.
magento-cloud integrations -p <project-ID>
3 - Webhook
Create a new webhook in your project repository to run the auto-deploy when some code is pushed.
You might find the configuration in this path below:
Repository Settings > Workflow > Webhooks
The URL to trigger the event must be the project URL reported in the step above, in the Hook URL.
+----------+-----------+--------------------------------------------------------------------------------+
| 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 |
+----------+-----------+--------------------------------------------------------------------------------+
4 - Create Cloud branch
The Bitbucket integration cannot activate new environments in your Magento Cloud 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 UI.
5 - Test
You just need to push something to your Bitbucket branch and see the Magento Cloud deploying it.
