Skip to content

GitLab CI/CD components - `tasks`

Description

Designing CI/CD pipelines in a way to make it possible to reuse pre-defined components is a common concept.

GitHub Actions, Azure Pipelines allow usage of reusable components:

  • A step can be a task or script and is the smallest building block of a pipeline.
  • A task is a pre-packaged script that performs an action, such as invoking a REST API or publishing a build artifact.

We do have templates and include but this solution is not flexible enough sometimes. It feels more like inheritance in object oriented programming than composition, and these are two entirely different concepts. Composition is sometimes considered more powerful, especially when a component that you want to inject needs extensive configuration and input data.

Proposal

Introduce ability to inject components into .gitlab-ci.yml using tasks directive. Similarly to what can be done with Azure Pipelines, but with some differences.

my-build:
  tasks:
    docker:build:
      image: my/image # resulting image
      tag: 123        # resulting tag
                       # GitLab registry credentials populated automatically
  script: docker images

We can use a separate docker container for every task, but we can also allow defining them in a generic way, so that users using shell executor can still benefit from using them

my-build:
  tasks:
    run-my-scripts:
      source: /my/project:v0.1 # link to a GitLab repository in the same instance
      args:                    # list of arguments that we will pass to a script
        - "something"

Perhaps it can be even more generic with docker-based task being defined in a repository first 🤔

Edited by Grzegorz Bizon