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.