5

I have a .gitlab-ci.yml which looks like this:

image: "python:3.7"

before_script:
  - pip install -r requirements.txt

stages:
  - stageA
  - stageB

stage_a:
  stage: stageA
  script:
  - run_some_python_scripts

stage_b:
  stage: stageB
  script:
  - run_more_python_scripts

With this setup, requirements.txt is installed before every stage. I need it installed only once, such that both stageA and stageB can use.

How can I achieve this?

Newskooler
  • 3,973
  • 7
  • 46
  • 84

1 Answers1

4

One option I've found that works great if the requirements.txt file doesn't change much, is to bake it into your own Docker image.

Another option which I personally don't like as much, is to use a virtualenv and then use GitLab's cache on the virtualenv, however this can be a bit slow if there are a lot of pip packages.

Rekovni
  • 6,319
  • 3
  • 39
  • 62
  • This is the best way to do it. For my projects I create a docker container and store it in GitLabs registry: https://docs.gitlab.com/ee/user/packages/container_registry/ – aknosis May 06 '20 at 15:53