Unable to SSH into my server using Gitlab CI Docker executor

I am unable to ssh into my server using Gitlab CI. I have tried every possible solution in Stack Overflow but still could not managed to solve it. :frowning:

This is the link that i used for reference: https://docs.gitlab.com/ee/ci/examples/deployment/composer-npm-deploy.html

My gitlab runner is running under a VM while my deployment server is running in another VM. Both of them are managed by VMWare ESXI. Gitlab runner is using Docker.

Things i have tried:

  1. Disabling the UFW firewall on my deployment server.
  2. Adding my deployment server ssh public key to Gitlab keys/
  3. Adding my private key into Gitlab variables.

Below is the script/yaml file that i use:

image: node:12.18.2

  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  - eval $(ssh-agent -s)
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  - mkdir -p ~/.ssh
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

    - node_modules/

#  - setup
#  - test
#  - build
  - deploy

#  stage: setup
#  script:
#    - npm install

#  stage: test
#  script:
#    - echo Testing...
#    - env CI=true npm test
#  stage: build
#  script:
#    - echo Building...
#    - npm run build
#  only:
#    - master

  stage: deploy
      - build/
    - ssh -A scim@
#    - ssh -A scim@ "mkdir /home/scim/Desktop/build_tmp"
#    - scp -r build/* scim@
#    - ssh scim@ "mv /home/scim/Desktop/build /home/scim/Desktop/build_old && mv /home/scim/Desktop/build_tmp /home/scim/Desktop/build"
#    - ssh server_user@server_host "rm -rf /home/scim/Desktop/build_old"
    - master

This is the error message that it produced on Gitlab UI.

Running with gitlab-runner 13.1.0 (6214287e)
  on docker-auto-scale 72989761
Preparing the "docker+machine" executor
Using Docker executor with image node:12.18.2 ...
Pulling docker image node:12.18.2 ...
Using docker image sha256:1fa6026dd8bbe97cf9d38fbf7e83b3f157aac1e28cad349a143c8920705771d6 for node:12.18.2 ...
Preparing environment
Running on runner-72989761-project-19942034-concurrent-0 via runner-72989761-srm-1594818580-ad6e18fc...
Getting source from Git repository
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/SaiMun92/SCIM_Webapp_Frontend/.git/
Created fresh repository.
Checking out 8edfe553 as master...
Skipping Git submodules setup
Restoring cache
Checking cache for master...
Downloading cache.zip from https://storage.googleapis.com/gitlab-com-runners-cache/project/19942034/master 
Successfully extracted cache
Executing "step_script" stage of the job script
$ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
$ eval $(ssh-agent -s)
Agent pid 13
$ ssh-add <(echo "$SSH_PRIVATE_KEY")
Identity added: /dev/fd/63 (saimun.lee@tauexpress.com)
$ mkdir -p ~/.ssh
$ [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
$ ssh scim@
Pseudo-terminal will not be allocated because stdin is not a terminal.
ssh: connect to host port 22: Connection timed out
ERROR: Job failed: exit code 1

My blunt first guess is that the 2 VM’s cant connect to each other.
try to add ping or traceroute to your script to check.
My other guess is that ssh needs something from you (key passphrase, not able to add known_hosts … ) . Add -v to your ssh command and see what ssh tells you.