In Azure Pipelines, I have enabled git tags to trigger pipelines like so:
trigger:
branches:
include:
- \'*\'
tags:
include:
- \'*\'
<
git describe can provide you with the (closest) tag name for a given git hash and Azure can give you the current hash with $(Build.SourceVersion)
.
Use the --exact-match
to limit git describe
to only use a tag from the specific commit:
git describe --exact-match $(Build.SourceVersion)
If there is a tag, it'll be returned on stdout:
$ git describe --exact-match d9df242
v1.0.0
If there is no tag, git describe --exact-match
exits with exit code 128:
$ git describe --exact-match cc1f9d2
fatal: no tag exactly matches 'cc1f9d23854c37dec000485c6c4009634516a148'
$ echo $?
128
so you can use this in a test or simply fail the task in pipelines that trigger on more than just tagged revisions.