Skip to content

GitLab CI/CD: Jobs that override before_script/after_script defaults require special handling #39

Closed
@dnsmichi

Description

@dnsmichi

Problem to solve

The following job overrides the default before_script section, thus resulting in a missing env file to source in the default after_script section.

build-cpp:
  stage: build
  #tags:
  #  - saas-linux-medium-amd64 
  image: gcc:9-bullseye 
  # TODO: Custom build image, this step wastes resources on every run 
  before_script:   ### THIS 
    - apt update && apt -y install cmake 
  script:
    - ci/build_cpp.sh

Proposal

Document how to use !reference to inherit the default before_script into jobs that define their own section.

build-cpp:
  stage: build
  #tags:
  #  - saas-linux-medium-amd64 
  image: gcc:9-bullseye 
  # TODO: Custom build image, this step wastes resources on every run 
  before_script:
    # Fix for tracepusher default overrides 
    - !reference [default, before_script]
    - apt update && apt -y install cmake 
  script:
    - ci/build_cpp.sh

This workaround only works as long as the default definition stays in the CI/CD configuration. When removed, the linters will throw errors.

Verified working in https://gitlab.com/gitlab-de/use-cases/observability/devsecops-efficiency/slow-pipeline-for-analysis/-/jobs/4593473836

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions