Build Configuration

The build section of the configuration file has several subsections which define at which point a command is executed. In most cases, the configuration inference will be able to determine the contents of these sections. If you do something special in your project, you can easily make tweaks to the inferred commands.

If you are just getting started, check out our language guides:

If you want to see all options at a glance, we have prepared a reference config for you.

Sections

The build sections are executed in the order below:

environment:This allows you to tweak the build environment if you are using our default image.
dependencies:This allows you to install additional code which is needed by your project.
project_setup:This allows you to make any project-specific set-up like creating a database and loading your schema.
tests:This section defines all your test commands.

Commands

Whenever you can specify a command in one of the sections, the command can be a simple string, or a hash defining some additional metadata:

build:
    tests:
        before:
            - 'this-is-a-simple-command'
            -
                command: 'this-is-a-complex-command'
                environment: { ABC: 'foo' }
                not_if: 'test -e foo/bar'
                only_if: 'test -e bar/baz'
                idle_timeout: 600
                background: true
                on_node: 1

Available Keys

command:The command which should be executed.
environment:A key-value hash with environment variables.
not_if:Skip command execution if the exit code is zero.
only_if:Skip command execution if the exit code is non-zero.
idle_timeout:The maximum time that no output has to be produced before considering the command timed out.
background:Whether to execute the command asynchronously in the background.
on_node:On which node to run the command if you want to run tests in parallel. Starts at 1.

Environment

Our default build environment uses Ubuntu 14.04 LTS and comes with several languages and common services pre-installed. This sections helps you fine tune this environment to your needs.

Languages

Java

Defines the Java runtime that should be used:

build:
    environment:
        java: 'java-8-oracle'

Pre-installed runtimes:

java-1.7.0-openjdk-amd64, java-7-oracle, and java-8-oracle

Node

Defines the node version that should be used:

build:
    environment:
        node: '0.12.4'

Pre-installed runtimes (you can also specify versions not listed here; these will be installed on-the-fly):

0.10.29, 0.11.13, 0.12.4, v4.2.2, v5.1.0, v6.2.0, iojs-v1.3.0, iojs-v1.8.4, iojs-v2.5.0, iojs-v3.3.1

PHP

Defines the PHP runtime which should be used:

build:
    environment:
        php: '5.5.25'

Pre-installed runtimes:

5.4.41, 5.5.25, 5.6.9, 5.6.16, 7.0.8, 7.0.20, 7.1.1, 7.1.6 and hhvm

Python

Defines the Python runtime which should be used:

build:
    environment:
        python: '2.7.7'

Pre-installed runtimes:

2.7.7, 3.2.5, 3.3.5, 3.4.1, 3.4.6, 3.5.0, 3.6.0, jython-2.5.3, jython-2.7.0, pypy-2.3.1, stackless-3.3.5, pypy-2.4.0, pypy-2.6.1, pypy-4.0.0, pypy-5.6.0, pypy2-5.6.0, pypy3-2.4.0, stackless-3.4.1

Ruby

Defines the Ruby runtime which should be used:

build:
    environment:
        ruby: '1.8.7-p375'

Pre-installed runtimes:

1.8.7-p375, 1.9.2-p320, 1.9.3-p547, 2.0.0-p481, 2.1.2, 2.1.5, 2.2.0, 2.2.3, 2.3.1, 2.4.0, jruby-1.7.9, 'jruby-1.7.19, jruby-9.0.4.0, jruby-9.1.1.0

Scala SBT

Defines the Scala SBT version which should be used:

build:
    environment:
        scala_sbt: 'sbt-0.13.2'

Pre-installed versions:

sbt-0.12.4, sbt-0.13.2

Apache2

If you would like your website to be accessible via the Apache webserver, you can define a basic set-up and we will generate the necessary configuration files automatically. You can optionally rewrite the Apache rules by adding them under the rule key.

build:
    environment:
        apache2:
            modules: ['rewrite']
            sites:
                symfony_app:
                    web_root: 'web/'
                    host: 'local.dev'
                    rules:
                        - 'RewriteCond %{HTTP_REFERER} !^$'
                        - 'RewriteCond %{HTTP_REFERER} !^http://(www.)?example.com/ [NC]'
                        - 'RewriteRule .(gif|jpg|png)$ - [F]'

The above configuration will generate the following configuration file for Apache2:

<VirtualHost *:80>
    DocumentRoot /home/scrutinizer/build/web/
    ServerName local.dev

    LogLevel warn
    ErrorLog /home/scrutinizer/artifacts/symfony_app-error.log
    CustomLog /home/scrutinizer/artifacts/symfony_app-access.log combined

    <Directory /home/scrutinizer/build/web/>
        Options All
        AllowOverride All
        Require all granted

        DirectoryIndex index.php
        DirectoryIndex app.php
    </Directory>

    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www.)?example.com/ [NC]
    RewriteRule .(gif|jpg|png)$ - [F]

    LoadModule php7_module /home/scrutinizer/.phpenv/versions/7.0/libexec/libphp7.so
    <FilesMatch \.php[0-9]*$>
        SetHandler application/x-httpd-php
    </FilesMatch>
</VirtualHost>

NGINX

Scrutinizer also allows you to access your website with NGINX webserver via PHP-FPM, we will automatically generate configuration files for NGINX based on your configuration.

build:
    environment:
        nginx:
            sites:
                symfony_app:
                    host: 'local.dev'
                    web_root: 'web/'

                    # These are optional and usually do not require changing.
                    index: 'index.php index.html'

                    # By default Scrutinizer will generate the following location block for the configuration file.
                    # But you can simply overwrite it with your own location blocks by adding them under ``locations``

                    locations:
                        - >
                           location ~ [^/]\.php(/|$) {
                               try_files $uri $uri/ /index.php /index.html;
                               fastcgi_index index.php;
                               fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                               fastcgi_pass 127.0.0.1:9000;
                               include fastcgi_params;
                           }
Note: PHP-FPM is using default address (127.0.0.1:9000). Please set fastcgi_pass to 127.0.0.1:9000 in your location block.

For the above configuration, we will generate following configuration file for Nginx:

# /etc/nginx/sites-enabled/symfony_app
server {
    server_name local.dev;

    root web/;
    index index.php index.html;

    location ~ [^/]\.php(/|$) {
        try_files $uri $uri/ /index.php /index.html;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
    }

    error_log /home/scrutinizer/artifacts/nginx-symfony_app-error.log;
    access_log /home/scrutinizer/artifacts/nginx-symfony_app-access.log;
}

Elasticsearch

Elasticsearch is pre-installed in our build environment and can be enabled in your .scrutinizer.yml:

build:
    environment:
        elasticsearch: true

RabbitMQ

RabbitMQ is pre-installed in our build environment and can be enabled in your .scrutinizer.yml:

build:
    environment:
        rabbitmq: true

Setting the timezone

By default, we use UTC as timezone. If you need something else, just set the tz identifier in the configuration:

build:
    environment:
        timezone: 'US/Pacific'

Defining hostnames

If you would like to define custom hostnames, f.e. to be able to access the webserver via this host, you can define these in the environment section, too:

build:
    environment:
        hosts:
            local.dev: '127.0.0.1'

Selenium

If you would like to run Selenium tests, you can start a Selenium server configured with Firefox and Google Chrome. Simply add the following to your configuration:

build:
    environment:
        selenium: true

The Selenium server will then listen at the default address 127.0.0.1:4444. Please refer to our Selenium page for configuration details and installed versions.

Dependencies & Project Setup

These two sections define commands which should be run for installing additional dependencies, and setting up your project like creating a database. By default, Scrutinizer will try to infer the commands for these sections. You can add additional commands before or after the inferred commands and also override the inferred commands entirely.

build:
    dependencies:
        # Runs before inferred commands
        before:
            - 'gem install abc'
            - 'pecl install abc'
            - 'pip install Abc'

        # Overwrites inferred commands
        override:
            - 'some-command'

        # Runs after inferred commands
        after:
            - 'some-command'


    # Run after dependencies
    project_setup:
        before:
            - mysql -e "CREATE DATABASE abc"

        override: []
        after: []

If any of the commands in this section fails, your build is stopped.

Running Tests

Introduction

In this section, you can place your test commands. Test commands are special in that we execute all of them even if one them has already failed. This provides you with more debugging output:

build:
    tests:
        before:
            - 'bundle exec rspec'
            - 'vendor/bin/phpunit'

Parallel Tests

If you would like to run your tests in parallel, you can use the on_node flag.

build:
    tests:
        before:
            -
                command: 'vendor/bin/phpunit tests/SomeFolder'
                on_node: 1

            -
                command: 'vendor/bin/phpunit tests/AnotherFolder'
                on_node: 2

Generating Code Coverage

Scrutinizer can automatically process code coverage data. If you make use of parallelism, it will also automatically merge the coverage data from your different runs.

Learn more about generating code coverage data.