6 - Optimize CI-CD Pipeline & Configure Multi-Stage Pipeline

2 - Configure Dynamic Versioning for Docker Image

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.

3 - Configure Caching to speed up Pipeline execution

In the first job that downloads dependencies:

# ...
run_unit_tests:
  # ...
  cache:
    key: "$CI_COMMIT_REF_NAME"
    paths:
      - app/node_modules

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.

Important

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:

4 - Testing in CI-CD & Configure Security Tests (SAST)

Different types of automated tests

Multi-Stage Deployments

Her method does not distinguish deployment environments by branch (gitflow).