Learn how to set up Magento Cloud Bitbucket Integration. Our Magento Support team is here to help you with your questions and concerns.
Setting Up Magento Cloud Bitbucket Integration
Did you know that integrating Bitbucket with Magento Commerce (Cloud) is an excellent way to streamline our development workflow?
With this integration, every time we push code to Bitbucket, Magento Commerce Cloud will automatically build and deploy the environment.
Today, we will explore step-by-step how to set up this integration.
An Overview:
- Step 1: Prepare the Repository
- Step 2: Create an OAuth Consumer in Bitbucket
- Step 3: Configure the Integration
- Step 4: Create a Webhook for Auto-Deployment
- Step 5: Test the Integration
- Step 6: Branching and Environments
- Step 7: Remove the Integration
Step 1: Prepare the Repository
To begin, clone the Magento Commerce (Cloud) project to the local environment and then add it to a new, empty Bitbucket repository.
- First, log in to the Magento Cloud Project:
magento-cloud login
- Then, list the projects to find the Project ID:
magento-cloud project:list
- Next, clone the project to the local environment:
magento-cloud project:get project ID
Remember to replace the project ID with the actual project ID.
- Then, add the Bitbucket Repository as a remote:
git remote add origin git@bitbucket.org:user-name/repo-name.git
Remember to replace user-name and repo-name with the Bitbucket details.
- Now, it is time to remove the Default Magento Remote:
git remote remove magento
- Now, verify the remote setup:
git remote -v show
- Then, push files to Bitbucket with this command:
git push -u origin master
At this point, our Bitbucket repository should contain all the project files.
Step 2: Create an OAuth Consumer in Bitbucket
Bitbucket integration requires an OAuth consumer to authenticate and interact with Magento Commerce Cloud.
- First, log in to our Bitbucket Account.
- Then, go to Settings > Access Management > OAuth and click on Add Consumer.
- After that, it is time to configure the OAuth Consumer. We can leave the Callback URL empty but must provide some value for the field.
- Finally, save the Consumer, then copy the OAuth key and secret for the next step.
Step 3: Configure the Integration
Now, set up the Bitbucket integration using the Magento Cloud CLI and the OAuth credentials.
- We have to create a Temporary JSON File. So, open a terminal and create a `bitbucket.json` file as seen here:
{
"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
}
We have to the placeholders with our own values.
- Then, add the Integration via the Magento Cloud CLI:
magento-cloud project:curl -p 'project_ID' /integrations -i -X POST -d "$(< bitbucket.json)"
- Once successful, we will see an HTTP status code `200` or `201`. If we see a `400` or above, it means an error occurred.
- Then, delete the temporary JSON File:
rm bitbucket.json
- Now, it is time to list the Project’s integration:
magento-cloud integrations -p 'project_ID'
Step 4: Create a Webhook for Auto-Deployment
We need to configure a webhook in our Bitbucket repository to enable automatic deployment.
- Go to `Repository Settings > Workflow > Webhooks in Bitbucket.
- Then, add a New Webhook with the following format for the URL:
https://magento-url.cloud/api/projects//integrations/<int-id>/hook
Step 5: Test the Integration
After setting up the integration, we have to verify that it’s working correctly by pushing a small change to our Bitbucket repository.
- Create a test file:
touch test.md
- Then, commit and push the file with this command:
git add . && git commit -m "Testing Bitbucket integration" && git push
- Next, log in to the Magento Cloud Console to verify that our commit message is visible and the project is deploying automatically.
Step 6: Branching and Environments
The Bitbucket integration doesn’t create new environments automatically. Hence, we must use the Magento Cloud CLI to create new branches:
For example:
- Create a new branch in the local environment:
git checkout -b new-branch
- Then, push the branch to Bitbucket:
git push -u origin new-branch
Any changes to this branch will trigger automatic builds and deployments.
Step 7: Remove the Integration
Furthermore, we can remove the Bitbucket integration without affecting our code.
- First, list the integrations to get the integration ID:
magento-cloud integration:list
- Then, delete the integration:
magento-cloud integration:delete ID
Here, we have to replace ID with the actual integration ID.
Alternatively, we can revoke the OAuth token from the Bitbucket account settings.
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
By following these steps, we can set up Bitbucket integration with Magento Commerce (Cloud) to automate our build and deployment processes. This integration boosts efficiency, allowing us to focus more on development and less on manual deployments.
In brief, our Support Experts demonstrated how to set up Magento Cloud Bitbucket Integration.
0 Comments