Egorrko
Egorrko

Reputation: 63

Gitlab CI in docker. Disable cleaning directory before stage starts

I decided to build my pipeline on this plan:

  1. Build stage: Run only if the branch is the main one or one of my build files has been modified. It inherits docker:latest, and builds a test-ready container (pytest, lint) and pushes it to the local registry.
  2. Test stage: always runs, inherits the latest or own branch container from the previous stage. All tests are run in it.
  3. Push to production: it doesn't matter now.

Problems in 2 stage:

I run the ls -la command and I don't see my venv, node_modules folders. I thought GIT_CLEAN_FLAGS would solve my problem. But it didn't help.

How reproduce the problem:

Building image

FROM python:3.7-slim
ARG CI_PROJECT_DIR
WORKDIR $CI_PROJECT_DIR
RUN pip install -r requirements.txt
build:
  stage: build
  tags:
    - build
  script:
    - docker build --build-arg CI_PROJECT_DIR=$CI_PROJECT_DIR .

Test

lint:
  variables:
    GIT_CLEAN_FLAGS: none
  stage: test
  tags:
    - test
  script:
    - pwd
    - ls -lah

Upvotes: 0

Views: 603

Answers (1)

Egorrko
Egorrko

Reputation: 63

You don't need to use CI_PROJECT_DIR. Save your code in another directory: /my-app for example.
And in your second stage use cd /my-app.

Code example of your second stage:

test:
  stage: test
  tags:
    - test
  before_script:
    - cd /my-app
  script:
    - pwd
    - ls -lah

Upvotes: 1

Related Questions