Configure Bitbucket Pipelines

Edit on GitHub

This document describes how to configure continuous integration using Bitbucket Pipelines.

Bitbucket Pipelines

Bitbucket Pipelines is an integrated CI/CD service, built into Bitbucket. It allows you to automatically build, test, and deploy your code, based on a configuration file in your repository.

For more information on Bitbucket Pipelines, see Get started with Bitbucket Pipelines.

Prerequisites

  1. In the repository root, create the CI/CD configuration file: bitbucket-pipelines.yml.
  2. To choose the language, create a basic pipeline template and environment variables, follow Get started with Bitbucket Pipelines.
Secured variables

To make the values of environment variables hidden in logs, set up secured variables. See Variables and secrets for details.

Configuring basic validation with Bitbucket Pipelines

Configure services and a basic validation of:

  • code style
  • architecture
  • security
  • database schema
Example of bitbucket-pipelines.yml
image: spryker/php:7.4-debian

pipelines:
  default:
    - step:
        size: 2x
        name: 'validation'
        caches:
          - composer
          - node
        script:
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - apt-get update && apt-get install -y unzip && apt-get install -y nodejs && apt-get install -y npm
          - npm install && npm test
          - composer install --optimize-autoloader --no-interaction
          - vendor/bin/install $APPLICATION_STORE -r testing -x frontend -x queue -v
          - vendor/bin/phpstan analyze -c phpstan.neon src/ -l 4
          - vendor/bin/console propel:schema:validate
          - vendor/bin/console propel:schema:validate-xml-names
          - vendor/bin/console transfer:validate
          - vendor/bin/console code:sniff:style
          - vendor/bin/phpmd src/ text vendor/spryker/architecture-sniffer/src/ruleset.xml --minimumpriority 2
          - node ./frontend/libs/stylelint
          - node ./frontend/libs/tslint stylish
        services:
          - mysql
          - redis
          - elasticsearch
          - broker

definitions:
  services:
    mysql:
      image: mariadb:10.3
      variables:
        MYSQL_USER: $MYSQL_USER
        MYSQL_PASSWORD: $MYSQL_PASSWORD
        MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
        MYSQL_DATABASE: $MYSQL_DATABASE
    redis:
      image: redis:5.0-alpine
    elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:6.8.4
      environment:
        ES_JAVA_OPTS: '-Xms512m -Xmx512m'
    broker:
      image: spryker/rabbitmq:3.7.14
      environment:
        RABBITMQ_DEFAULT_USER: $RABBITMQ_DEFAULT_USER
        RABBITMQ_DEFAULT_PASS: $RABBITMQ_DEFAULT_PASS
        RABBITMQ_DEFAULT_VHOST: $RABBITMQ_DEFAULT_VHOST

To adjust the services used in the configuration, see Configure bitbucket-pipelines.yml.

Configuring groups of tests

Docker SDK tests will be supported after Bitbucket starts supporting Docker BuildKit. We will update this document with the configuration instructions.

To set up a job that runs a specific group of tests:

  1. To bitbucket-pipelines.yml, add the following configuration template:
...
    - step:
        image: spryker/php:{image_tag}
        name: 'tests'
        size: 2x
        caches:
            - composer
            - node
        script:
            - echo $APPLICATION_STORE
            - curl --location --output installer.sig https://composer.github.io/installer.sig
            - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
            - php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
            - php composer-setup.php
            - php -r "unlink('composer-setup.php'); unlink('installer.sig');"
            - php composer.phar config -g github-oauth.github.com $GITHUB_ACCESS_TOKEN
            - apt-get update && apt-get install -y unzip && apt-get install -y nodejs && apt-get install -y npm
            - npm install && npm test
            - composer install --optimize-autoloader --no-interaction
            - vendor/bin/install $APPLICATION_STORE -r testing -x frontend -x queue -v
            - APPLICATION_ENV=devtest vendor/bin/codecept run -c {tests_configuration_file}
  1. Replace the placeholders with the actual values using the following description.
PLACEHOLDER DESCRIPTION EXAMPLE IN THE PROPERTY VALUE
{image_tag} Tag of the Docker image on which the validation is based. Check all the images in the Spryker Docker hub. 7.4
{tests_configuration_file} Codeception configuration files that defines the tests to run. Example: codeception.ci.functional.yml codeception.functional.yml