Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

git - 如何在Azure管道中获取Git标记(How to get Git Tag in Azure Pipelines)

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

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

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

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?

    (管道是从git commit还是git标签开始的?)

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

    (如果管道是从git标签启动的,标签名称是什么?)

  ask by Muhammad Rehan Saeed translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When you configure the pipeline to be triggers with tag the meaning that when new tag is pushed the pipeline start to run.

(当您将管道配置为使用标签触发时,意味着按下新标签时管道开始运行。)

so:

(所以:)

1) The pipeline will start from the git tag.

(1)管道将从git标签开始。)

2) I don't understand the question, if you pushed tag test so the tag name will be test .

(2)我不明白这个问题,如果您按下标签test那么标签名称将为test 。)

If you want to know programmatically if the build trigger was a tag and what is the tag name you can check the environment variable Build.SourceBranch if the build is from a tag the value will be: refs/tags/tagName .

(如果您想通过编程方式了解构建触发器是否是标签以及标签名称是什么,则可以检查环境变量Build.SourceBranch如果构建来自标签),则值将为: refs/tags/tagName 。)

So just add a PowerShell task and print the value:

(因此,只需添加一个PowerShell任务并打印值即可:)

Write-Host $env:Build_SourceBranch

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...