0

Here is my yml file:

stages:
 - stage1

job1:
  stage: stage1
  script:
  - >
    #!/bin/sh
    cd .
    echo "checking whether the ctl file exists"
    if [ -s something.ctl ]
    then
      echo "exists"
    else 
      echo "does not exist, exiting gitlab pipeline"
      exit -1
    fi

When the pipeline runs it fails with exit code 2 and I see this message in the log:

Syntax error near unexpected token `else'

What do I need to change here?

Anky
  • 1
  • 2

2 Answers2

0

This script section work (using bash shell) :

  script:
  - cd .
  - echo "checking whether the ctl file exists"
  - >
    if [ -s something.ctl ]; then
      echo "exists";
    else 
      echo "does not exist, exiting gitlab pipeline";
      exit 1;
    fi

Also be aware that to exit a job properly, code must be 0 (succeed) or 1 (fail)

Nicolas Pepinster
  • 5,413
  • 2
  • 30
  • 48
0

The issue resolved after I replaced "- >" with "- |-"

so now my file looks like

script:
   - |-
   echo "..."
   echo....
Anky
  • 1
  • 2