1

I've tried setting up Travis CI on a new empty Magento 2 Github repo (https://github.com/Tjitse-E/TravisTest).

Part of my Travis configuration file:

install:
   - echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > auth.json
   - composer install --no-interaction --prefer-dist
   - mysql -e 'DROP DATABASE IF EXISTS magentotravis'
   - mysql -e 'CREATE DATABASE IF NOT EXISTS magentotravis;'
   - php bin/magento setup:install --base-url=http://magebuild.integrations.p1-test.de/build/
     --db-host=localhost --db-name=test --db-user=root --admin-firstname=test
     --admin-lastname=Demo --admin-email=test@test--admin-user=test
     --admin-password=72q980hdfq2378ga9w87dg6 --language=de_DE --currency=EUR --timezone=Europe/Berlin
   - php bin/magento setup:upgrade
   - php bin/magento setup:di:compile
   - php bin/magento cache:clean
   - php bin/magento index:reindex

I've intentionally installed a module that triggers an error/warning with the command php bin/magento setup:di:compile. I want Travis CI to recognize the error and then stop the build. Would this be possible?

Travis output:

41.78s$ php bin/magento setup:di:compile
Compilation was started.
%message% 0/7 [>---------------------------]   0% 1 sec 46.0 MiB%message% 0/7 [>---------------------------]   0% 1 sec 46.0 MiBProxies code generation... 0/7 [>---------------------------]   0% 1 sec 46.0 MiB
Proxies code generation... 1/7 [====>-----------------------]  14% 1 sec 52.0 MiB
Repositories code generation... 1/7 [====>-----------------------]  14% 1 sec 52.0 MiB
Repositories code generation... 2/7 [========>-------------------]  28% 5 secs 154.0 MiB
Service data attributes generation... 2/7 [========>-------------------]  28% 5 secs 154.0 MiB
Service data attributes generation... 3/7 [============>---------------]  42% 5 secs 154.0 MiB
Application code generator... 3/7 [============>---------------]  42% 5 secs 154.0 MiB
Application code generator... 4/7 [================>-----------]  57% 13 secs 174.0 MiB
Interceptors generation... 4/7 [================>-----------]  57% 13 secs 174.0 MiB
Interceptors generation... 5/7 [====================>-------]  71% 23 secs 192.0 MiB
Area configuration aggregation... 5/7 [====================>-------]  71% 23 secs 192.0 MiB
Area configuration aggregation... 6/7 [========================>---]  85% 33 secs 268.0 MiB
Interception cache generation... 6/7 [========================>---]  85% 33 secs 268.0 MiBErrors during compilation:
    Travis\Block\TestClass\TestClass
        Incorrect dependency in class Travis\Block\TestClass\TestClass in /home/travis/build/Tjitse-E/TravisTest/app/code/Travis/Sample/Block/TestClass.php
\Magento\Framework\App\Config\ScopeConfigInterface already exists in context object
Total Errors Count: 1
Errors during compilation:
    Travis\Block\TestClass\TestClass
        Incorrect dependency in class Travis\Block\TestClass\TestClass in /home/travis/build/Tjitse-E/TravisTest/app/code/Travis/Sample/Block/TestClass.php
\Magento\Framework\App\Config\ScopeConfigInterface already exists in context object
Total Errors Count: 1
Errors during compilation:
    Travis\Block\TestClass\TestClass
        Incorrect dependency in class Travis\Block\TestClass\TestClass in /home/travis/build/Tjitse-E/TravisTest/app/code/Travis/Sample/Block/TestClass.php
\Magento\Framework\App\Config\ScopeConfigInterface already exists in context object
Total Errors Count: 1
Interception cache generation... 7/7 [============================] 100% 40 secs 268.0 MiB
Generated code and dependency injection configuration successfully.

The purpose is to automatically test the DI of upgraded third party modules, because they sometimes contain errors in the constructor.

1

I've managed to get it working with the following line added to install:

- if php bin/magento setup:di:compile | grep "Errors during compilation"; then exit 1; fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.