Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Here are my build step : enter image description here

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.

like image 441
Xavier W. Avatar asked Feb 07 '23 15:02

Xavier W.


1 Answers

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

enter image description here

like image 59
Harshil Lodhi Avatar answered Feb 09 '23 12:02

Harshil Lodhi