How to get Git Tag in Azure Pipelines

前端 未结 8 1102
青春惊慌失措
青春惊慌失措 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:17

    This need to consider different situations. If you just push tag or create it with UI, the pipeline are started from git tag. Just commit without any tag, it will started from git commit. No doubt, the build will be triggered just once.

    But if you push commit with tag, the build will be triggered twice. First is triggered by commit, and second is by tag. Check this pic.

    These means the pipeline started from a commit instead of tag.

    All in all, no matter which is first, the tag which trigger the build are all you pushed or created.

    For getting more intuitive view about this, you can add variable ' $(Build.SourceBranch)' in your build number. Here is my code about how to configure build number in YAML file:

    name: $(Build.SourceBranch)-$(date:yyyyMMdd)$(rev:.r)
    trigger:
      branches:
        include:
        - '*'
      tags:
        include:
        - '*'
    

    Here is the result of what triggered the build. If tag, it will shows refs_tags_{tagname}, if it's commit, it will shows refs_heads_{branchname}.

提交回复
热议问题