Yes I know that tags and branches are not the same
The thing is, tags are associated with a commit, not directly to a branch so, in order to get the branch containing that commit you’d have to use something like git branch --contains <tag name>.
Maybe you could use that to get the branch name on pipelines that are run from a tag?
I strugled with the same problem. git branch --contains <commit> on MR run returned only detached HEAD at ... . No other branches (i.e. no branch the MR was comming from)
Solution for that was to use -r parameter, that forces to print the list of remote branches that given commit is associated with (they are visible on detached HEAD):