DEV Community

Nelson Hernández
Nelson Hernández

Posted on

How to reusing workflows with Gitlab CI/CD

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.

.gitlab-ci/node.yml

test:
  image: node:latest
  stage: test
  rules:
    - if: $CI_PIPELINE_SOURCE == "push"
  script:
    - node index.js
Enter fullscreen mode Exit fullscreen mode

.gitlab-ci.yml

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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)