How to get Git Tag in Azure Pipelines


In Azure Pipelines, I have enabled git tags to trigger pipelines like so:

    - '*'
    - '*'

Now I want to know if there is a way to determine programmatically:

  1. Was the pipeline started from a git commit or git tag?
  2. If the pipeline was started from a git tag, what is the tag name?


To check if the commit was from a tag, use:

startsWith(variables['Build.SourceBranch'], 'refs/tags/')

From James Thurley:

Get the name of the tag with:

$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.

I’ve removed the original answer and replaced it with the correct one from James Thurley. I’d delete my answer, but it appears you can’t delete an accepted answer.

Answered By – Alex Kaszynski

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published