Bitbucket Pipelines : interact with Posgresql database



First thing , I read and


For the settings I have no problem but I would to know how to interact with the database ?

For example, load a file of sql insert/create table via psql and then run test


Here is my config file : 

# This is a sample build configuration for Javascript.
# Check our guides at for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:6.9.5

    - step:
          # Step 1 : Install yarn with the easy way :
          - curl -o- -L | bash -s -- --version 0.23.4
          # Step 2: Belived
          # PATH variable should change like they said
          - export PATH=$HOME/.yarn/bin:$PATH
          #Allow to use mock controllers for test
          - export CONTROLLERS_FOR_TEST=TRUE
          # Step 3: Install app dependencies
          - yarn install
          #Allow to test app in production context
          - export NODE_ENV=production
          #Allow to specify the JWT TOKEN Signature (and not use OAuth0)
          - export SECRET_SIGNATURE_JWT_TOKEN=pokémon47
          #run the test with mock controllers
          - npm test
          - postgres

# Step 5: Start the test (real database)

      image: postgres:9.3

          #Code not working
          # - docker exec -ti postgres bash
          # prepare PostgreSQL
          # -  psql -U "postgres" -c "CREATE DATABASE custom_db" # create a new database
          # -  psql -U "postgres" -c "CREATE USER custom_user WITH PASSWORD 'custom_pass'" # create a new user : custom_user
          # -  psql -U "postgres" -d "custom_db" -f sql/database_tables.sql # create tables
          # -  psql -U "postgres" -d "custom_db" -f sql/database_grant.sql # give him the credentials
          # -  psql -U "postgres" -d "custom_db" -f sql/test_insert.sql # add basic data inside the database : some parkings and reasons
          # settings for running REST API
          # - export DB_HELPDESK_DB=custom_db
          # - export DB_HELPDESK_USER=custom_user
          # - export DB_HELPDESK_PASS=custom_pass
          # test

1 answer

0 votes

Two ways I can think of to interact with your databases; personally I would write a task in JS to interact with Postgres, so that you can run it with npm eg.

npm run load_db

You can also install the postgresql client from the OS packages. Node 6.9.5 is based on debian, so you can use apt-get to install the postgresql-client package.

apt-get update && apt-get install -qy postgresql-client

Thanks but I cannot start or run any psql command  .... Didn't forgot anything ?


postgres -D /var/lib/postgresql/data
pg_ctl -D /var/lib/postgresql/data -l logfile start


aren't working ...

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 14, 2019 in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

311 views 0 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you