creating a reusable pipeline can be very beneficial to reduce duplicate code and also to standardize across other pipelines in the same project or across other projects. For

let’s start by defining the reusable pipeline

Create a new pipeline

pipeline.yml

variables:
  VAR1: ""
  VAR2: ""
  VAR3: ""

stages:
 - stage1
 - stage2
 - stage3

job_1:
  stage: stage1
  image:
    name: some-image
  variables:
    SOME_VARIABLE_1: "$VAR1"
  script:
    - echo 'Do something with $SOME_VARIABLE_1 like validate/lint '
  
job_2:
  stage: stage2
  image:
    name: some-image
  variables:
    SOME_VARIABLE_2: "$VAR2"
  script:
    - echo 'Do something with $SOME_VARIABLE_2 like build/test'
  

job_3:
  stage: stage3
  image:
    name: some-image
  variables:
    SOME_VARIABLE_3: "$VAR3"
  script:
    - echo 'Do something with $SOME_VARIABLE_3 like deploy to specfic environment based on the input variable'

Use The pipeline

.gitlab-ci.yml

stages:
  - trigger
  
development_flow:
  stage: trigger
  only:
    refs:
      - /^feature/.*$/
  variables:
    VAR1: "alex"
    VAR2: "123"
    VAR3: "DEVELOP"
  trigger:
    include: pipeline.yml
    
stage_flow:
  stage: trigger
  only:
    refs:
      - /^release/.*$/
  variables:
    VAR1: "john"
    VAR2: "456"
    VAR3: "STAGING"
  trigger:
    include: pipeline.yml
    
production_flow:
  stage: trigger
  only:
    refs:
      - master
  variables:
    VAR1: "john"
    VAR2: "456"
    VAR3: "PRODUCTION"
  trigger:
    include: pipeline.yml
  

As you can see you can now reuse the pipeline that was defined in a single file and standardized that across your different environments with minimal duplication of code. if you choose to add another step to your overall process all you have to do is add that to your pipeline.yml file.yml

Bonus points

Bonus points if you define your pipeline in a separate repository and version it by tagging. that way you can import it into other projects.yml

to do that you in just import it like so in your main file

include:
  - project: "your-repo-that-hosts-the-reusable-pipeline"
    ref: 1.0.0
    file: pipeline.yml