Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to connect to external server through SSH

a-kopchinskiy_apollo4u June 29, 2020

How to connect to external server through SSH?

 

My config:

image: node:latest

pipelines:
default:
- parallel:
- step:
script:
- ssh ubuntu@<host-ip-here>
- step:
script: # Modify the commands below to build your repository.
- curl https://google.com # SUCCESS
- step:
script: # Modify the commands below to build your repository.
- curl 172.16.0.14 # ERROR
- step:
script: # Modify the commands below to build your repository.
- curl 172.17.0.1 # ERROR
- step:
script: # Modify the commands below to build your repository.
- curl <host-ip-here> # ERROR
- step:
script: # Modify the commands below to build your repository.
- curl localhost # ERROR
- step:
script: # Modify the commands below to build your repository.
- curl 127.0.0.1 # ERROR
- step:
script: # Modify the commands below to build your repository.
- curl host.docker.internal # ERROR

 

Bitbucket shows that SSH connection is successful, but all of the curl commands failed, excepts google.com

What I'm doing wrong?

2 answers

1 accepted

1 vote
Answer accepted
a-kopchinskiy_apollo4u July 10, 2020

I found the solution:

script:      
- ssh -fN user@<server-ip> -L *:1234:localhost:1234 # opening SSH tunnel to the authorization service

- npm run test-integration -- --config config-bitbucket-pipeline.json

As connection address in the test script itself I use http://localhost:1234

 

p.s. This Bitbucket community is so helpful, OMG! 😂

0 votes
ktomk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2020

It looks like you're running the curl commands in the step script but you want to run them on the SSH host.

Have you tried to run the command(s) via SSH instead?

a-kopchinskiy_apollo4u June 30, 2020

It looks like you're running the curl commands in the step script but you want to run them on the SSH host.

No, it's not how it looks like.

I need to create SSH tunnel to my host for my integration tests in Bitbucket Pipelines, because all databases are there.
Run command with SSH on the remote server is senseless, because I need to check connection of the Docker container to remote server through SSH tunnel.

(docker container)-[SSH tunnel]-(remote server)

I just want to know 2 things:

1. Does Bitbucket Pipelines allow to use docker localhost address (like host.docker.internal), because it's necessary for SSH tunnel.

2. Is it possible with Bitbucket Pipelines to run integration tests which are using databases, having these databases on a remote server?

ktomk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2020

Ah ok, I now better understand for what you need the SSH connection: tunnel to other remote server(s) not within the pipelines network from within a pipeline step script.

I have no experience with that in Bitbucket Pipelines, but what looks fishy to me in your original parallel step scripts is that only one of those step scripts does open the ssh tunnel. As this is not a service, nor the other steps would reference such a service, this should not be available in the other step scripts.

Additionally please see: How can I use SSH in Bitbucket Pipelines?

----

1. Does Bitbucket Pipelines allow to use docker localhost address (like host.docker.internal), because it's necessary for SSH tunnel.

In the end this depends on the container the step scripts runs in, by default I would assume this does not work out of the box. Have not tested it.

2. Is it possible with Bitbucket Pipelines to run integration tests which are using databases, having these databases on a remote server?

If the remote server is publicly available via the internet, you should get connectivity. I would say this is not ideal to increase the distance to the build system, but as you describe it in your scenario, you need to do it.

It might not be common / easy to setup. See as well: How to use VPN with Bitbucket Pipelines

a-kopchinskiy_apollo4u July 9, 2020

I need SSH connection to obtain authorization token from external service for integration testing inside pipelines.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events