How debug before_script? I dont see output before_script

Hello!
There is a gitlab-ci configuration that uses docker registry, which is provided by gitlab itself

build:
  stage: build
  image: "$build_img"
  artifacts:
    paths:
    - assembly/target
  script:
    - 'mvn clean package'

.test_template: &test_template
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker build --pull -t "$CI_REGISTRY_IMAGE/$CI_PROJECT_NAME/$CI_JOB_NAME:$CI_COMMIT_REF_SLUG" .
    - docker run --name "$CI_PROJECT_NAME"-db-"$CI_PIPELINE_ID"-"$CI_JOB_NAME" -d "$pgsql_img"
    - docker run --name "$CI_PROJECT_NAME"-"$CI_PIPELINE_ID"-"$CI_JOB_NAME" --link "$CI_PROJECT_NAME"-db-"$CI_PIPELINE_ID"-"$CI_JOB_NAME":db -d "$CI_REGISTRY_IMAGE/$CI_PROJECT_NAME/$CI_JOB_NAME:$CI_COMMIT_REF_SLUG" java -jar main.jar

it_unit_test:
  stage: test
  image: "$build_img"
  dependencies:
    - build
  services:
    - name: "$pgsql_img"
      alias: db
  script:
    - mvn test -P intTests

The configuration works.

I’m redoing it on nexus docker registry.

build:
  stage: build
  image: "$build_img"
  artifacts:
    paths:
    - assembly/target
  script:
    - 'mvn clean package -Dmaven.test.skip=true'

.test_template: &test_template
  before_script:
    - docker login -u login1111 -p password11111 docker-registry.11111.local:5000
    - docker build --pull -t "$CI_PROJECT_NAME:$CI_COMMIT_TAG" .
    - docker run --name "$CI_PROJECT_NAME"-db-"$CI_PIPELINE_ID"-"$CI_JOB_NAME" -d "$pgsql_img"
    - docker run --name "$CI_PROJECT_NAME"-"$CI_PIPELINE_ID"-"$CI_JOB_NAME" --link "$CI_PROJECT_NAME"-db-"$CI_PIPELINE_ID"-"$CI_JOB_NAME":db -d "$CI_REGISTRY_IMAGE/$CI_PROJECT_NAME/$CI_JOB_NAME:$CI_COMMIT_REF_SLUG" java -jar main.jar

test_containers:
  stage: test
  <<: *test_template
  script:
    - TEST=`docker exec --tty "$CI_PROJECT_NAME"-"$CI_PIPELINE_ID"-"$CI_JOB_NAME" wget -qO /dev/stdout http://localhost:8088/monitoring/selftest`
    - echo $TEST
    - if [[ -z `echo $TEST | grep OK` ]]; then echo "Error - $TEST" && exit 254; else echo OK; exit 0; fi

it_unit_test:
  stage: test
  image: "$build_img"
  dependencies:
    - build
  services:
    - name: "$pgsql_img"
      alias: db
  script:
    - mvn test -P intTests

An error appears

SEVERE: Connection error: 
org.postgresql.util.PSQLException: The connection attempt failed.

After added echo and id to gitlab-ci.yaml:
echo pgsql_img pgsql_img pgsql_img docker-registry.XXXXXXXXXX:10443/postgres:9.6 id
uid=502(gitlab-runner) gid=501(gitlab-runner) groups=501(gitlab-runner),502(docker)
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ping db
ping: db: Name or service not known
ERROR: Job failed: exit status 1

I think issue in before_script
How debug before_script?
I dont see output before_script

Hi @patsev.anton

In your first yml, your .test_template section defines the before_script
This section has been defined as a YAML Anchor and you’ll need to include it in the job you want to use it.
In the second yml, it’s been included in the test_containers job with this line:

  <<: *test_template

you’ll need a similar line in one (or both) of your jobs in the first yml

Thank you