In Azure Pipelines, I have enabled git tags to trigger pipelines like so:
trigger:
branches:
include:
- \'*\'
tags:
include:
- \'*\'
<
The accepted answer using git tag -l v*
didn't work for me as it didn't order the tags correctly, instead giving 1.1, 1.11, 1.12, 1.2, 1.3, etc
.
I found it better to do:
$tags = git tag --sort=-creatordate
$tag = $tags[0]
This sorts the tags correctly for both annotated and unannotated tags, and so the first result is the most recent tag.
According the this doc the Tag which started the build can be found in BUILD_SOURCEBRANCH
.
If this build was queued by the creation of a tag then this is the name of that tag. For Azure Pipelines, the BUILD_SOURCEBRANCH will be set to the full Git reference name, eg refs/tags/tag_name.