How to run jobs based on submodule branch name?

I have the following pipeline stages:

Build -> Install -> Run -> Test Output

Repo A
- Repo B as a submodule

Run A, test output of A
Run B, test output of B
Run C, test output of C

Run B and C take a long time, so I only want to run A and test A UNLESS the submodule branch checked out is ‘staging’ branch. Is there a way to do this? I tried to grep the .gitmodules ‘branch’ line and assign a variable to it in before_script, but I don’t think the jobs’ rules can see this variable? Is there a way to do this? (Run jobs only if submodule branch checked out is x)

As far as I can tell, submodule awareness is not available when the pipeline plan is evaluated for execution. Variables in rules are also evaluated prior to any execution, so they cannot be dynamically influenced by scripts running after.

For more dynamic behavior at execution, you can perhaps “generate” the jobs you’d like to run by leveraging the dynamic child pipeline feature, after gathering information about the revisions.