agardnerIT / tracepusher

Generate and push OpenTelemetry Trace data to an OTEL collector in JSON format
Apache License 2.0
53 stars 11 forks source link

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

Closed dnsmichi closed 1 year ago

dnsmichi commented 1 year ago

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

agardnerIT commented 1 year ago

I think this is solved with the standalone binaries available in 0.8.0. We can re-open if it is still relevant.