In Azure Pipeline is possible use predefined build variables (DevOps Services) Build.SourceBranch and Build.SourceBranchName but their values at case commit with tag are tags.
In doc. https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#build-variables-devops-services is written
- When your pipeline is triggered by a tag: refs/tags/your-tag-name
- The name of the branch in the triggering repo the build was queued for. Git repo branch or pull request: The last path segment in the ref. For example, in refs/heads/master this value is master. In refs/heads/feature/tools this value is tools.
- this my observation: but in case commit with tag is the last path segment of Build.SourceBranch, so your-tag-name