Question

ssh time out only when use gitlab runner

Posted January 8, 2020 3.4k views
CI/CD

I use gitlab ci/cd and my gitlab-ci.yml looks like this:

stages:
  - deploy
  - build
build_image:
  stage: build
  image: docker/compose
  services:
    - docker:dind
  variables:
    DOCKER_DRIVER: overlay
    PHP_SSH_PORT: 23
    JANGAL_SERVER_PORT: 80
    VENDOR_DIR: /var/www/vendor
    LOCAL_PHP_IP: 0.0.0.0
    MYSQL_PORT: 3307
    LOCAL_DEV_DIR: /home/centos/www/order-managment
  script:
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
    - docker-compose  -p jangal-${CI_COMMIT_REF_SLUG} build --pull
    - docker-compose push
  only:
    - master
deploy_staging:
  stage: deploy
  image: rastasheep/ubuntu-sshd:latest
  variables:
    DOCKER_DRIVER: overlay
    PHP_SSH_PORT: 23
    JANGAL_SERVER_PORT: 80
    VENDOR_DIR: /var/www/vendor
    LOCAL_IP: 0.0.0.0
    MYSQL_PORT: 3307
    LOCAL_DEV_DIR: /home/centos/www/order-managment
  script:
    # add the server as a known host
    - ssh-keyscan staging.jangal.com >> ~/.ssh/known_hosts
    - chmod 600 ~/.ssh/known_hosts
    # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
    - eval $(ssh-agent -s)
    - touch key.txt
    - echo "$SSH_PRIVATE_KEY" >> key.txt
    - chmod 600 key.txt
    - ssh-add key.txt
    - ssh -vT -o ConnectTimeout=10 -o BatchMode=yes -o StrictHostKeyChecking=no deployer@staging.jangal.com
    # log into Docker registry
    - ssh deployer@37.152.177.29 "sudo HTTPS_PROXY=159.203.87.130:3128 docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com"
    # stop container, remove image.
    - ssh deployer@37.152.177.29 "docker ps --format '{{.Names}}' | grep "^jangal-${CI_COMMIT_REF_SLUG}" | awk '{print $1}' | xargs -I {} docker stop {}" || true
    - ssh deployer@37.152.177.29 "docker ps --format '{{.Names}}' | grep "^jangal-${CI_COMMIT_REF_SLUG}" | awk '{print $1}' | xargs -I {} docker rm {}" || true
    - ssh deployer@37.152.177.29 "docker ps --format '{{.Names}}' | grep "^jangal-${CI_COMMIT_REF_SLUG}" | awk '{print $1}' | xargs -I {} docker rmi {}" -f || true
    # remove .env
    - ssh deployer@37.152.177.29 "./start.sh"
  only:
    - master

Only on gitlab-runner when i try to ssh deployer@37.152.177.29 on server i have error like:

1 Running with gitlab-runner 12.6.0-rc1 (ec299e72)
2   on docker-auto-scale ed2dce3a
3
Using Docker executor with image rastasheep/ubuntu-sshd:latest ...
00:17
4 Pulling docker image rastasheep/ubuntu-sshd:latest ...
5 Using docker image sha256:49533628fb371c9f1952c06cedf912c78a81fbe3914901334673c369376e077e for rastasheep/ubuntu-sshd:latest ...
7
Running on runner-ed2dce3a-project-15949603-concurrent-0 via runner-ed2dce3a-srm-1578459988-75cd4adf...
00:05
9
$ eval "$CI_PRE_CLONE_SCRIPT"
00:01
10 Fetching changes with git depth set to 50...
11 Initialized empty Git repository in /builds/Junglepub/order-managment/.git/
12 Created fresh repository.
13 From https://gitlab.com/Junglepub/order-managment
14  * [new ref]         refs/pipelines/107717344 -> refs/pipelines/107717344
15  * [new branch]      master                   -> origin/master
16 Checking out 4abb00af as master...
17 Skipping Git submodules setup
21
$ ssh-keyscan staging.jangal.com >> ~/.ssh/known_hosts
00:16
22 $ chmod 600 ~/.ssh/known_hosts
23 $ eval $(ssh-agent -s)
24 Agent pid 14
25 $ touch key.txt
26 $ echo "$SSH_PRIVATE_KEY" >> key.txt
27 $ chmod 600 key.txt
28 $ ssh-add key.txt
29 Identity added: key.txt (key.txt)
30 $ ssh -vT -o ConnectTimeout=10 -o BatchMode=yes -o StrictHostKeyChecking=no deployer@staging.jangal.com
31 OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n  7 Dec 2017
32 debug1: Reading configuration data /etc/ssh/ssh_config
33 debug1: /etc/ssh/ssh_config line 19: Applying options for *
34 debug1: Connecting to staging.jangal.com [37.152.177.29] port 22.
35 debug1: connect to address 37.152.177.29 port 22: Connection timed out
36 ssh: connect to host staging.jangal.com port 22: Connection timed out
40 ERROR: Job failed: exit code 11 Running with gitlab-runner 12.6.0-rc1 (ec299e72)
2   on docker-auto-scale ed2dce3a
3
Using Docker executor with image rastasheep/ubuntu-sshd:latest ...
00:17
4 Pulling docker image rastasheep/ubuntu-sshd:latest ...
5 Using docker image sha256:49533628fb371c9f1952c06cedf912c78a81fbe3914901334673c369376e077e for rastasheep/ubuntu-sshd:latest ...
7
Running on runner-ed2dce3a-project-15949603-concurrent-0 via runner-ed2dce3a-srm-1578459988-75cd4adf...
00:05
9
$ eval "$CI_PRE_CLONE_SCRIPT"
00:01
10 Fetching changes with git depth set to 50...
11 Initialized empty Git repository in /builds/Junglepub/order-managment/.git/
12 Created fresh repository.
13 From https://gitlab.com/Junglepub/order-managment
14  * [new ref]         refs/pipelines/107717344 -> refs/pipelines/107717344
15  * [new branch]      master                   -> origin/master
16 Checking out 4abb00af as master...
17 Skipping Git submodules setup
21
$ ssh-keyscan staging.jangal.com >> ~/.ssh/known_hosts
00:16
22 $ chmod 600 ~/.ssh/known_hosts
23 $ eval $(ssh-agent -s)
24 Agent pid 14
25 $ touch key.txt
26 $ echo "$SSH_PRIVATE_KEY" >> key.txt
27 $ chmod 600 key.txt
28 $ ssh-add key.txt
29 Identity added: key.txt (key.txt)
30 $ ssh -vT -o ConnectTimeout=10 -o BatchMode=yes -o StrictHostKeyChecking=no deployer@staging.jangal.com
31 OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n  7 Dec 2017
32 debug1: Reading configuration data /etc/ssh/ssh_config
33 debug1: /etc/ssh/ssh_config line 19: Applying options for *
34 debug1: Connecting to staging.jangal.com [37.152.177.29] port 22.
35 debug1: connect to address 37.152.177.29 port 22: Connection timed out
36 ssh: connect to host staging.jangal.com port 22: Connection timed out
40 ERROR: Job failed: exit code 1

I have checked this ssh and every where except gitlab ci it return ttime out, even i build docker on my system and ssh was good. can someone tell me why only on gitlab runner it return time out on ssh connect

edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Hello, @alirezarahmani

Looking at the provided output, you were not able to reach staging.jangal.com on port 22 at that time. At the moment the host seems up and I can confirm that this port is open so you should be able to connect now.

Could you please confirm if you’re still experiencing the same issue?

Regards,
Alex

No @alexdo only on gitlab runner it returns time out. I do not understand what is wrong with gitlab runner?

Submit an Answer