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?
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! 😂
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need SSH connection to obtain authorization token from external service for integration testing inside pipelines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.