0

I'm trying add mongodb on my bitbucket pipeline but I've the following error:

Uncaught MongoError: failed to connect to server [localhost:27017] on first connect

My bitbucket-pipelines.yml:

image: leeduc/pipelines-node-mongo

pipelines:
  default:
    - step:
        script
          - npm install
          - npm test
          - npm run eslint

Any idea to solve that ?

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
1fabiopereira
  • 472
  • 2
  • 4
  • 15
  • I believe the error is because I can not access the standard port of the mongo inside the container, but I have no idea how to solve this – 1fabiopereira Dec 09 '16 at 11:47

4 Answers4

0

Try to run some checks before build commands, for example on Ubuntu: service mongodb status . Your task is to see if mongodb really running at that monent.

Oleksandr Diudiun
  • 4,194
  • 1
  • 12
  • 7
0

It seems like you need a helping mongo DB service and fortunately Bitbucket now allows you to run helping services in the pipeline. I haven't tried it but this document should be helpful.

Let me know if it doesn't make sense I will see if I can add an example.

Qasim Sarfraz
  • 3,923
  • 2
  • 15
  • 24
0

Unfortunately pipelines doesn't wait for a service image to be downloaded and be up and running before start the execution of your scripts so you should manage that in your code

Nico
  • 1,091
  • 1
  • 11
  • 26
0

I use Mongo in pipelines with Node images, I usually add Mongo as a service.

for Node:

image: node:13.8.0
pipelines:
  default:
   - step:
      name: Build and Test
      script: 
        - npm ci
        - npm run test
      services: # must also be defined below, in the end of the file
        - mongo # added to run the integration tests with MongoDB

  custom: # Can only be triggered manually
    deploy-to-production: 
      - step:
          name: Deploy to Production
          script:
               …. # call script here
definitions: 
  services: 
    mongo: 
      image: mongo
Cadesh
  • 1
  • 3