How to fail a build on Scrutinizer based on phpcs output?

450 views Asked by At

I've tried configuring Scrutinizer to fail whenever the CodeSniffer analysis returns some errors with no luck.

Here's what I tried so far:

V1:

build:
  tests:
    override:
        command: './vendor/bin/phpcs ./src --report=checkstyle --report-file=cs-data'
        analysis:
          file: 'cs-data'
          format: 'php-cs-checkstyle'

V2:

build:
  tests:
    override:
      - 'phpcs-run'

My tools and build_failure_conditions:

tools:
  php_code_sniffer:
    config:
      standard: "PSR2"
checks:
  php:
    code_rating: true
    duplication: true
build_failure_conditions:
  - 'issues.label("coding-style").new.exists'

What's missing?

1

There are 1 answers

0
Andrei On BEST ANSWER

TLDR; It looks like you're not specifying which folders to scan for errors.

Try using the following:

build:
  tests:
    override:
      - 'phpcs-run --standard=custom/standard/ruleset.xml --ignore=app/*/*/Test/ app/dir1/ app/dir2/ app/other/folder'

Some things that required clarification for me:

  • scrutinizer currently does not support failing the phpcs command (similar to phpunit) as that would prevent the issues from being displayed in the UI.
  • the workaround for that is to set-up a failure condition (which you already did) like for example whether there are coding-style issues, then that would fail the build.

I'm currently using:

build_failure_conditions:
  - 'issues.label("coding-style").new.exists'

Which makes the inspection look like this

More info about how to set-up failure conditions: https://scrutinizer-ci.com/docs/configuration/build_status