如何在Azure管道中获取Git标记 [英] How to get Git Tag in Azure Pipelines

查看:75
本文介绍了如何在Azure管道中获取Git标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Azure管道中,我启用了git标签来触发管道,如下所示:

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

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

现在我想知道是否有一种方法可以通过编程确定:

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

  1. 管道是从git commit还是git标签开始的?
  2. 如果管道是从git标签启动的,标签名称是什么?

推荐答案

要检查提交是否来自标签,请使用:

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

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

来自James Thurley:

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.

我已经删除了原始答案,并用詹姆斯·瑟利(James Thurley)的正确答案代替了它.我会删除我的答案,但看来您无法删除接受的答案.

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.

这篇关于如何在Azure管道中获取Git标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆