I want to establish a gitlab test stage that uses a gitlab service postgres database. The problem is, that everytime I try to access the database via a script call in the pipeline I get the following error:
psql: error: could not connect to server: Connection refused
Is the server running on host "postgres" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
yaml looks the following
image: some_image:latest
stages:
- test
tests:
image: node:latest
stage: test
services:
- postgres:latest
before_script:
- apt-get update && apt-get install -y postgresql-client libpq-dev
# access database script from another repo here through git clone
- psql -U postgres -h postgres < ./create-database.sql
script:
- npm install
- npm run tests
only:
- master
Am I missing something - is the database maybe not created and I am calling to soon?
CodePudding user response:
You're missing the configuration properties of the DB. They can not be configured on the UI - or they can but won't be passed to the actual DB service. So please add the following properties to the script:
variables:
POSTGRES_DB: <db name>
POSTGRES_USER: <db user>
POSTGRES_PASSWORD: <some PW>
POSTGRES_HOST_AUTH_METHOD: trust
Documentation link: https://docs.gitlab.com/ee/ci/services/postgres.html