How we use BitBucket Pipelines for continuous integration (CI)

Magento 2 was designed with automated testing in mind from the very beginning. This approach, often called test-driven development (TDD), means code and software are tested automatically. You can see right away whether new code or changes affect other parts of the system. In general, this improves code quality and prevents bugs and errors that…

🗓

Magento 2 was designed with automated testing in mind from the very beginning. This approach, often called test-driven development (TDD), means code and software are tested automatically. You can see right away whether new code or changes affect other parts of the system. In general, this improves code quality and prevents bugs and errors that would otherwise only surface when a new version of Magento is released.

We’ve been exploring automated testing for a while, but until now, it never gave us the insight or the solution we were after. We tried several tools, including Bamboo and Jenkins, two of the most widely used options for automated testing. So when we got the chance to join the BitBucket Pipelines beta, we jumped at it to see whether this platform would be a better fit for us.

We shared our first experiences with BitBucket Pipelines at Mage Unconference, where we showed other developers how we use the tool. Several attendees said it would be helpful to share this more widely, so we wrote this article.

BitBucket Pipelines is an add-on to BitBucket, the popular tool for managing Git repositories. It lets you run automated tests, and its defining feature is simplicity: add a “bitbucket-pipelines.yml” file to your Git repository, and the build process starts.

The technology runs on Docker images, which start up for every build. We chose a Docker image from MageInferno that’s specifically designed for running Magento 2, so there’s no need to install any additional software. Then we define the build steps. First, we allocate the right amount of memory. Next, Magento 2 is installed using composer install. We then automatically run CodeSniffer on our own custom code to detect coding violations, followed by all of Magento 2’s unit tests to make sure no standard Magento functionality has broken.

Example bitbucket-pipelines.yml

image: mageinferno/magento2-php:7.0.8-fpm-3

pipelines:
 default:
 - step:
 script:
 - sed -i "s/PHP_MEMORY_LIMIT/2G/" /usr/local/etc/php/php.ini
 - composer install --prefer-dist
 - ./dev/scripts/run-codesniffer.sh
 - ./dev/scripts/run-unit-tests.sh

BitBucket itself gives you an excellent overview of every build that runs, as you can see in the screenshot below. We’ve set up Pipelines to run a build on every commit, so developers get immediate feedback on whether their code meets our standards or contains errors.

bitbucket-succesfull

Click a build to see the details. The logs are grouped by step from the bitbucket-pipelines.yml file, so you can quickly find the results of any specific step. This makes it easy to pinpoint issues. A developer can fix them and push a new commit, which immediately restarts the process to check whether the changes work as intended.

bitbucket-logs

Our initial results have been very positive, so we’ve decided to roll out BitBucket Pipelines across all our projects. We’re also looking into building against different PHP versions, and into using BitBucket Pipelines to handle deployments to test and production environments as well.

Related updates

Explore more blog posts and updates from Cream

Ready to get started?

Looking for a new Magento online store, or want to migrate your current platform to future-proof Magento? Get in touch to find out how we can help your online store grow.