In this lecture it's explained how needs
differs from dependencies
. Note: when needs is used, dependencies is not needed.
At 30 min she talks about Dotenv files
Create a build.env
file during the job. The contents must be key=value
.
And then use this:
# ...
build_image:
# ...
artifacts:
reports:
dotenv: build.env
This automatically makes the key
variable available for the next stages.
dependencies
or needs
keywords can be used to control which jobs receive these env vars.In the first job that downloads dependencies:
# ...
run_unit_tests:
# ...
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- app/node_modules
key
:
default
$CI_COMMIT_REF_NAME
paths
Note that the cache
key has 2 different purposes:
On 1st execution, the job generates the cache. On 2nd execution, the job ca re-use its own cache.
policy
pull-push
job downloads the cache when the job starts & uploads changes to the cache when the job ends (note: that's the default behavior, you don't need to specify)pull
only download the cache, but never upload changes (use when you have many jobs executing in parallel using the same cache).push
common to have a job, which just builds the cache (will only upload a cache, but never download).
Your job should never depend on a cache to be available. Caching is an optimization, but it isn't guaranteed to always work.
Notes about the [Clear runner caches]
button on GitLab's UI:
Different types of automated tests
Her method does not distinguish deployment environments by branch (gitflow).