how to run a gitlab job only when corresponding code is updated

I will start with a description of a project and then ask a question.

The Context:

  1. there is a monorepo ( managed by pnpm )
  2. there are three projects in the monorepo: libCommon, serverA, serverB
  3. the libCommon is a dependency of the serverA and serverB

What I try to achieve:

  1. whenever code for serverA gets pushed to gitlab, I need a job that builds and deploys the serverA gets executed. No other job, but just this one.
  2. whenever code for serverB gets pushed to gitlab, I need a job that builds and deploys the serverA gets executed. No other job, but just this one.
  3. whenever code for libCommon gets pushed, I need both the serverA job, and the serverB job get executed.

I am totally new to this and have no idea where to start looking for answers.

Hi @dmitry.n.medvedev
you can use rules keyword as described in the docs
Your rule could look like this:

job:serverA:
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
      changes:
      - serverA/*
      - libCommon/*
    - when: never
  script:
    - your steps
  ...other stuff...

job:serverB:
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
      changes:
      - serverB/*
      - libCommon/*
    - when: never
  script:
    - your steps
  ...other stuff...