Script ran from Gitlab CI-CD stopped without completing

I have set up gitlab ci-cd in which I call a script to perform some task on my server.

  stage: production
  # when: manual
    - "which ssh-agent || ( apk update && apk add openssh-client )"
    - ssh [email protected]$DEPLOY_SERVER 'bash -s' < ./
    - master

Now inside, I checked if docker is installed or not as:


set -e

which docker || ( sudo apt update -y && sudo apt install apt-transport-https ca-certificates curl software-properties-common -y && curl -fsSL | sudo apt-key add - && sudo add-apt-repository "deb [arch=amd64] bionic stable" -y && sudo apt update -y && sudo apt-cache policy docker-ce && sudo apt install docker-ce )

sudo docker version

... continue performing the tasks

The problem is if docker is installed then the tasks from sudo docker version to the end of the script is executed.

But if docker is not installed, i.e which docker fails, then the required packages are installed but then the tasks below all fail to execute and gitlab-cicd show Job succeeded without executing other tasks below from sudo docker version to the end.

What is the reason?

Source: StackOverflow