1

I try to make a http request to some host and if http status code is not 200 GitLab pipeline job should fail.

How I can make GitLab job to fail?

But job succeeded.

Here is script section of my gitlab-ci.yml:

  script:
    - 'if [ $(curl -X POST -s -o stdout -w "%{http_code}" -I https://example.com) -eq 200 ]; then exit 1; fi'

enter image description here

  • 1
    ‘_But job succeeded_’ The log shows the code was 200, so what did you expect? – Biffen May 26 '23 at 10:52
  • 2
    How about just `curl -X POST --fail https://example.com`? That _should_ exit non-zero on non-200 (but do read the documentation) and IFAIK that should fail the whole job. – Biffen May 26 '23 at 10:55
  • @Biffen, sure I meant negative test in this case. Not -ne but -eq operator. But in fact this is doesn't matter because approach with `--fail` option is a solution. Thank you! – pixelpenguin May 26 '23 at 11:18
  • 1
    @Biffen what could you propose for `Recv failure`? It seems the `--fail` option doesn't work this way – anatol Jul 06 '23 at 13:46

0 Answers0