Gitlab-ci: bash tests don't work

Hi all,

I tried to use bash tests in my ci-job. However, all tests I tried seem to be considered true (or maybe ignored). In the example below, both echo statements are executed!
Do you have any ideas on that?

Thanks!

    -   if [ 1 -lt 2 ]
    -   then
    -     echo foo
    -   fi
    -   if [ 2 -lt 1 ]
    -   then
    -     echo foo
    -   fi

The problem is that the if statements do not report a correct return status to the following commands. I think it is related to this bug in gitlab runners (not sure though).

  • So you can either join the then with the if clause:
-  if [ 2 -lt 1 ]; then
- echo foo
- fi

This still is a poor solution because it doesn’t protect you against the bug.

  • The best solution is to use multi-line script or write your own script and include it with you source files.
multi-line-script:
  script:
    - |
      if [ 1 -lt 2 ]
      then
        echo foo
      fi
      if [ 2 -lt 1 ]
      then
        echo bar
      fi
run-own-script
  script:
    - chmod u+x your_script.sh
    - ./your_script.sh
    - # or just bash -s your_script.sh 

Thanks a lot for the comprehensive answer!
Your solution works fine and the multi-line script even better :slight_smile: