2

Using a shell executor with powershell, allow_failure:exit_codes do not behave as documented https://docs.gitlab.com/ee/ci/yaml/#allow_failureexit_codes

With the following very simple job:

build:
    script:
        - exit 4
    allow_failure:
      exit_codes:
        - 4

The job fails instead of passing with a warning sign.

It works perfectly with bash. it works perfectly with allow_failure: true.

Am I missing something ? Is there a work around ?

Mathieu Westphal
  • 2,544
  • 1
  • 19
  • 33
  • 1
    This is probably a facet of how Powershell works, in general. See [returning an exit code](https://stackoverflow.com/questions/50200325/returning-an-exit-code-from-a-powershell-script). [This issue](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/28244) suggests that using `"$host.SetShouldExit($code); exit $code"` is a workaround. Could you try that? – sytech Jun 21 '22 at 16:51

1 Answers1

1

This is an aspect of how Powershell works, in general. See: Returning an exit code from a PowerShell script

To workaround this for a shell executor running powershell, use the following:

script:
  - $host.SetShouldExit(4); exit 4
# ...

Note, however this workaround may not work for custom executors, like the beta shared-windows autoscaling executors on gitlab.com -- there is no workaround in that case at this time of writing.

sytech
  • 29,298
  • 3
  • 45
  • 86