Set exit code zero if condition is met

Hi folks,

On my build I have a UI test code to execute after my web widget is fullu initialized.
So, I have to wait for my widget services to be live.
I try to query this service with wget . However wget returns exit code as 8 if my service is fully accessible. I try to set exit code to 0 with below logic. But not able to set it to 0 as circle ci still gets exit code as 8

      - run:
      background: true
      command: java -jar target/chatbot.jar
  - run: |
      wget --waitretry=5 --retry-connrefused --tries=12  -v http://localhost:3011/
      if [[ "$RESULT" = "8" ]]; then exit 0

  - run:
      name: Integration Test
      command: testcafe chrome:headless test/integration/*.js

Any help will be appreciated. Thanks

1 Like

Hi @nesatuf and welcome to the developer’s forum!

To recap, you would like the exit 8 to translate to an exit 0, but the job is still exiting with code 8. Is that correct?

This is most likely happening because the job ends after a non-0 exit code. So that means when this command wget --waitretry=5 --retry-connrefused --tries=12 -v http://localhost:3011/ returns an exit 8, the job ends and it does not continue to the “RESULT” command.

We do currently have a feature request open to allow for additional exit codes:
Our product managers review feature requests regularly, and if a request that you voted on has been implemented as a feature, you will automatically receive an e-mail updating you.

1 Like

Hi @annapamela

Yes, you interpret the situation very well. Thanks.

I think, I have found a workaround at your suggested feature request

For future reference to others;
Run your code at once like below:
bash -c “wget --waitretry=5 --retry-connrefused --tries=12 -v http://localhost:3011/; if [[ $? -eq 8 ]] ; then exit 0 ; else exit 1 ; fi”

Thank you

1 Like

Thank you for sharing the workaround! That is very clever!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.