How to retrieve Git commit id and message in VSTS/TFS build?

浪子不回头ぞ 提交于 2019-12-03 17:21:50

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

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

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

Following command will display the latest commit id and commit message:

git log --pretty=oneline | head -1

You can create a power-shell script task in the build definition to get the commit comment and write it to a text file via Rest API.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!