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)