How to import a yml file based on condition?

Present we kept multiple pipelines in separate yml files and all of them are included in the mail ci yml file.
using include statements.

Is there anyway to make it conditional.

Like I will have pipeline1 and pipeline2 yaml files.

So I can create another pipeline.yml where I can choose among the above two files based on some condition.

include:rules looks like a good solution to this.

tried as per your suggestion.
But when I moved few stages to a different yaml file and kept include as below. It is stating the aws file as invalid file.
In that aws file, I didn’t keep the variables and rules macros as they are in common yml file but getting this error.


include:
 - local: .gitlab/.gitlab-create-admin-common.yml
 - local: .gitlab/.gitlab-create-admin-aws.yml
   rules:
    - if: $CLOUD_PLATFORM == "aws"
 - local: .gitlab/.gitlab-create-admin/.gitlab-create-admin-gcp.yml
   rules:
    - if: $CLOUD_PLATFORM == "gcp"

And it is working if I keep the same variables and macros of rules to the aws file again.
Which is repetitive code.

I’m not sure quite what the issue is here. Presumably you’ve run the files through the CI lint already, so I think these docs might be relevant to you.

I defined all my pipeline variables in a separate file and used the import, but it is giving error as invalid yaml.

include:
 - local: .gitlab/.gitlab-create-admin-variables.yml

In CI LInt, it is showing only option to check syntax of individual files and include can’t test.

Also I tried like this to import a yml file based on condition and skip another if that variable is specified, but getting below error.

include:
 - local: .gitlab/.gitlab-create-admin-common.yml
 - local: .gitlab/.gitlab-test-setup-script.yml
   rules:
    - if: '$CLOUD_PLATFORM == "aws" && $TEST_SETUP'
 - local: .gitlab/.gitlab-create-admin-aws.yml
   rules:
    - if: $TEST_SETUP
      when: never
    - if: $CLOUD_PLATFORM == "aws"
 - local: .gitlab/.gitlab-create-admin-gcp.yml
   rules:
    - if: $CLOUD_PLATFORM == "gcp"
#### Found errors in your .gitlab-ci.yml:

* invalid include rule: {:if=>"$TEST_SETUP", :when=>"never"}

You can also test your .gitlab-ci.yml in [CI Lint](https://gitlab.com/projectnn/krypton/-/ci/editor?tab=LINT_TAB)

image