How to get Git Tag in Azure Pipelines

前端 未结 8 1091
青春惊慌失措
青春惊慌失措 2021-02-07 07:28

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

trigger:
  branches:
    include:
    - \'*\'
  tags:
    include:
    - \'*\'
<         


        
8条回答
  •  遥遥无期
    2021-02-07 08:24

    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.

提交回复
热议问题