如何在 VSTS/TFS 构建中检索 Git 提交 ID 和消息? [英] How to retrieve Git commit id and message in VSTS/TFS build?

查看:26
本文介绍了如何在 VSTS/TFS 构建中检索 Git 提交 ID 和消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 VSTS 的 CI 环境中,我想获取提交注释以将他设置为文本文件.

I'm in a CI environment using VSTS and I want to get the commit comment to set him into a text file.

这是我的构建步骤:

这个想法是将 GIT 提交注释复制到存储在工件文件夹中的文本文件中.然后使用 HockeyApp SDK,我将在 relase note 中设置我的提交评论.

The idea is to copy the GIT commit comment into a text file stored in the artifact folder. Then with the HockeyApp SDK, i'll set my commit comment in the relase note.

我可以通过命令行操作轻松复制文件,但我不知道如何检索评论.

I can easily copy the file with a command line operation, but I do not know how the retrieve the comment.

推荐答案

环境变量$(Build.SOURCEVERSIONMESSAGE) 在构建过程中设置.您可以直接在任务输入中使用 $(build.SOURCEVERSIONMESSAGE) 访问它.

The environment variable $(Build.SOURCEVERSIONMESSAGE) is set during build. You can access it using $(build.SOURCEVERSIONMESSAGE) directly in your task inputs.

如果您想在 powershell 脚本或内联 powershell 脚本中访问它.您可以通过环境变量访问它,即 Get-Item Env:BUILD_SOURCEVERSIONMESSAGE

If you want to access it in a powershell script or inline powershell script. You can access it via the environment variable i.e. Get-Item Env:BUILD_SOURCEVERSIONMESSAGE

以下脚本将在二进制文件夹中创建一个新文件 commit.txt,其中包含提交消息.使用具有内联类型的 Powershell 任务运行脚本.

The following script will create a new file commit.txt in the binaries folder with commit message in it. Run the script using the Powershell task with inline Type.

$message = (Get-Item Env:BUILD_SOURCEVERSIONMESSAGE)

$path =  (Get-Item Env:BUILD_BINARIESDIRECTORY).Value + 'commit.txt'

echo $message > $path

这篇关于如何在 VSTS/TFS 构建中检索 Git 提交 ID 和消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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