Sending back exit signal to gitlab pipeline

77 Views Asked by At

Is there any way to send back exit signal from the bash script to the GitLab pipeline script?

What I'm trying to do simple looks like:

install:
  stage: install
  
  script:
    - |
       echo "Dummy dry-run installation"
       chmod +x ./install-dry-run.sh
       ./install-dry-run.sh $SA_EMAIL $PROJECT_ID
  rules:
    - when: never

and bash script:

gcloud compute ssh ${instance_name} \
--quiet --tunnel-through-iap --zone=us-east4-c --ssh-key-expire-after=30s \
--project=${PROJECT_ID} \
--impersonate-service-account=${SA_EMAIL} \
--command="\
  if [ -f "/path/to/my/file.txt" ]; then echo 'Process successful'; else echo 'Process failed'; exit 1 > /dev/null; fi \
  " \
  -- -n

but that will not fail when the file is not present.

PS. Proposed solution didn't worked:

Process failed
$ if [ $? -ne 0 ]; then # collapsed multi-line command
Installation successful
1

There are 1 best solutions below

0
JackTheKnife On BEST ANSWER

Working but kind of "dirty" solution for install-dry-run.sh :

gcloud compute ssh ${instance_name} \
--quiet --tunnel-through-iap --zone=us-east4-c --ssh-key-expire-after=30s \
--project=${PROJECT_ID} \
--impersonate-service-account=${SA_EMAIL} \
--command="\
  if [ -f "/path/to/my/file.txt" ]; then echo 'success'; else echo 'failure'; fi; \
  " \
-- -n > status.txt

if grep -q failure status.txt; then
   echo "Installation failed"
   exit 1
else 
   echo "Installation successful"
fi