The available environment variables have this:
CI_BRANCH
The name of the source branch that Xcode Cloud checked out for the current build, for example, main.
However, this is only available for builds started by a branch change. I tried using it in a manual build, and it was just an empty string. Is there a way to get the branch name for manually started workflows? You have to choose a branch to start one, so I'd assume that info is available somewhere.