To reuse a workflow in GitLab CI/CD, you can use the
include keyword in your
.gitlab-ci.yml file. This keyword allows you to include the contents of another .gitlab-ci.yml file in your current file, effectively allowing you to reuse a workflow across multiple projects or repositories.
To use the include keyword, you first need to create a file containing the workflow you want to reuse. This file should contain the
.gitlab-ci.yml syntax for defining your workflow, including any jobs, stages, and dependencies.
test: image: node:latest stage: test rules: - if: $CI_PIPELINE_SOURCE == "push" script: - node index.js
stages: - test - build include: - local: /.gitlab-ci/node.yml build: image: python:latest stage: build rules: - if: $CI_PIPELINE_SOURCE == "push" script: - python main.py