Exit code not being respected

Trying to integrate Snyk with my GitLab.com SaaS pipeline. The snyk test command will return exit code 1 if any issues. For initial phase I want to allow the pipeline to succeed if exit_code == 1.

maven-snyk: 
  script:
    - snyk monitor --maven-aggregate-project --target-reference=$CI_COMMIT_REF_NAME
    - snyk test 
  allow_failure:
    exit_codes: 1

The above job ends with “ERROR: Job failed: command terminated with exit code 1”, which is expected but the job still fails.

  script:
    - snyk monitor --maven-aggregate-project --target-reference=$CI_COMMIT_REF_NAME
    - snyk test || EXIT_CODE=$?
    - echo $EXIT_CODE
    - exit $EXIT_CODE

The above script will echo 1 but pipeline still fails.

Any advice?

Hi there,

Yes, job will always fail when exit code is different then 0. What allow_failure does, is instead of showing failure, shows “warning” (orange instead of red icon on the job), and pipeline can continue. At the end of pipeline, it should show something like “Pipeline succeeded with warnings”

1 Like

I came back to delete my post after seeing this different icon, and you are completely correct. I’ll leave this post up as its not very intuitive when you are learning.

Thanks Paula.

2 Likes