'gitlab CI/CD: How to check for variable but also allow to run when using web UI

I want to check for a variable value before triggering the pipeline. But at the same time i dont want to check the variable value when its triggered from web ui manually

stages:
  - build

build:
  stage: build
  script: 
   - // do something
  only: // HERE WANT TO CHECK THE VARIABLE VALUE WHEN ITS NOT TRIGGERED FROM WEB UI
    variables:
      - $UPSTREAM_PROJECT == "A"
  // BUT HOW TO NOT CHECK THE VARIABLE VALUE WHEN ITS TRIGGERED USING WEB UI

How to do this.



Solution 1:[1]

rules: must be used for this use case.

build:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "web"'
    - if: '$UPSTREAM_PROJECT == "A"'
  # ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sytech