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

后端 未结 3 1387
孤独总比滥情好
孤独总比滥情好 2021-02-10 22:42

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 :

The idea is to copy the GIT comm

相关标签:
3条回答
  • 2021-02-10 22:52

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

    git log --pretty=oneline | head -1
    
    0 讨论(0)
  • 2021-02-10 22:59

    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.

    0 讨论(0)
  • 2021-02-10 23:07

    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
    

    0 讨论(0)
提交回复
热议问题