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.
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:
- Disabling the UFW firewall on my deployment server.
- Adding my deployment server ssh public key to Gitlab keys/
- Adding my private key into Gitlab variables.
Below is the script/yaml file that i use:
image: node:12.18.2 before_script: - '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' cache: key: "$CI_COMMIT_REF_NAME" paths: - node_modules/ stages: # - setup # - test # - build - deploy #setup: # stage: setup # script: # - npm install #test: # stage: test # script: # - echo Testing... # - env CI=true npm test # #build: # stage: build # script: # - echo Building... # - npm run build # only: # - master deploy: stage: deploy artifacts: paths: - build/ script: - ssh -A email@example.com # - ssh -A firstname.lastname@example.org "mkdir /home/scim/Desktop/build_tmp" # - scp -r build/* email@example.com:/home/scim/Desktop/build_tmp # - ssh firstname.lastname@example.org "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" only: - 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 00:39 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 00:05 Running on runner-72989761-project-19942034-concurrent-0 via runner-72989761-srm-1594818580-ad6e18fc... Getting source from Git repository 00:02 $ eval "$CI_PRE_CLONE_SCRIPT" 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 00:15 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 00:33 $ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y ) /usr/bin/ssh-agent $ eval $(ssh-agent -s) Agent pid 13 $ ssh-add <(echo "$SSH_PRIVATE_KEY") Identity added: /dev/fd/63 (email@example.com) $ mkdir -p ~/.ssh $ [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config $ ssh firstname.lastname@example.org Pseudo-terminal will not be allocated because stdin is not a terminal. ssh: connect to host 192.168.100.201 port 22: Connection timed out ERROR: Job failed: exit code 1