I am relatively new to gitlab and have figured out how to create and run a CI/CD pipeline which works quite well. Nonetheless, it runs relatively slow, as I currently repeatedly create the required environment in different jobs using before_script
.
So what I want is to once install a bunch of packages and then re-use them in different jobs. I know that one would normally create a docker image for this and re-use it to run the CI. But here, I am interested in the possibility to re-use the state of different jobs in subsequent jobs.
Here's a minimal example that explains my problem and what I want to achieve:
stages:
- prepare
- stage1
- stage2
image: python
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
.prepare_step1:
before_script:
- pip install requests
prepare-env:
image: python:3.7
stage: prepare
tags:
- docker
extends:
- .prepare_step1
script:
- pip list
run-first-job:
stage: stage1
tags:
- docker
script:
# I want to re-use the complete last state of the "prepare-env" stage here
# i. e. use the installed requests package
- pip list
run-second-job:
stage: stage2
tags:
- docker
script:
# I want to re-use the complete last state of the "prepare-env" stage here
# i. e. use the installed requests package
- pip list
I know about artifacts and caching but I am not sure if these are made to transfer the entire state of the Docker container of the prepare-env
job into the subsequent jobs run-first-job
and run-second-job
i.e. only install the packages once and then use them in other jobs.
Any hints are welcome, thanks in advance!