1

I am looking for a way to fail build pipeline when there are logged any errors. I have found many situations(npm, unit test, and other) when exception/errors/problems occurs causing in pipeline to log and show errors but build pipeline results in SUCCESS(no one feel need to check details because pipeline passed and shows green SUCCESS and that is the problem).

Three tasks('script', 'Bash', 'Powershell') have option "failOnStderr" (set to true makes step failing when anything is written to stderr) which seems to be exact resolution to this problem, but other tasks(like 'vstest', 'cake build' and other) do not have.

Yaml scheme for 'task' does not provide option to fail task when error is logged.

Thank you for your help : ]

1 Answer 1

2

For this issue , there are some scenarios that can cause this. I sort out several situations and workarounds here:

Npm : This means your script "swallows" the exit code and exits normally. you need to add a check to your script that would catch the exit code of your npm run lint and exit with the same exit code, something like:

- script: |
    npm install
    npm run lint # Mapped to `eslint src` in package.json
    if [ $? -ne 0 ]; then
        exit 1
    fi
    npm run slint # `stylelint src` in package.json
    npm run build

Please refer to this case for details.

Test: You can try to add failTaskOnFailedTests: true in the task inputs,for example:

- task: PublishTestResults@2
  inputs:
    testRunner: VSTest
    testResultsFiles: '**/*.trx'
    failTaskOnFailedTests: true

Please refer to this case for details.

Defects in a version of the task itself may also cause this phenomenon. In this case, there is either a circular symlink or just too many files in the original path that the helper that was looking through the files failed. The bug is the helper reported success. This issue ended up by updating the Maven task with a newer version of the task library.

In addition, if you use self-hosted agent to run build pipeline, older versions of the agent may also cause this situation. The solution is to update the agent to the latest version. You can refer to this for details.

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for answer, npm problem is solved now. Unfortunately I am using VSTest@2 which automatically publishes test results. Do you know how to resolve this problem for this task? Errors happen when exception is thrown and it causes test to be skipped so vstest thinks everything is OK.
Any updates on this? I finding the same thing, 3 years later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.