Bobcares

Setting Up Magento Cloud Bitbucket Integration

by | Sep 21, 2024

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

Setting Up Magento Cloud Bitbucket IntegrationDid 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

To begin, clone the Magento Commerce (Cloud) project to the local environment and then add it to a new, empty Bitbucket repository.

  1. First, log in to the Magento Cloud Project:

    magento-cloud login

  2. Then, list the projects to find the Project ID:

    magento-cloud project:list

  3. 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.

  4. 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.

  5. Now, it is time to remove the Default Magento Remote:

    git remote remove magento

  6. Now, verify the remote setup:

    git remote -v show

  7. 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.

  1. First, log in to our Bitbucket Account.
  2. Then, go to Settings > Access Management > OAuth and click on Add Consumer.
  3. 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.
  4. 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.

  1. 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.

  2. Then, add the Integration via the Magento Cloud CLI:

    magento-cloud project:curl -p 'project_ID' /integrations -i -X POST -d "$(< bitbucket.json)"

  3. Once successful, we will see an HTTP status code `200` or `201`. If we see a `400` or above, it means an error occurred.
  4. Then, delete the temporary JSON File:

    rm bitbucket.json

  5. 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.

  1. Go to `Repository Settings > Workflow > Webhooks in Bitbucket.
  2. 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.

  1. Create a test file:

    touch test.md

  2. Then, commit and push the file with this command:

    git add . && git commit -m "Testing Bitbucket integration" && git push

  3. 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:

  1. Create a new branch in the local environment:

    git checkout -b new-branch

  2. 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.

  1. First, list the integrations to get the integration ID:

    magento-cloud integration:list

  2. 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

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF