需要GIT命令列出TFS构建中的关联提交

时间:2019-01-14 01:59:05

标签: git powershell github tfs

我具有滚动构建(批处理CI BUILD),该构建针对每次提交运行。

我想编写一个PowerShell脚本,该脚本为我们提供该构建的相关提交细节。

我需要确切的Git命令来获取这些详细信息。

有人可以帮助我获得此命令吗?

1 个答案:

答案 0 :(得分:1)

您可以使用Builds - Get Build Changes Rest API。

PowerShell脚本例如:

$buildId = 1999
$url = http://{tfsServer}:8080/tfs/{collection}/{teamProject}/_apis/build/builds/$($buildId)/changes?api-version=3.0

$response = Invoke-RestMethod -Uri $url -ContentType application/json -Method GET -UseDefaultCredentials

Write-Host "The associated commits to build $($buildId): `n"

For ($i=0; $i -le $response.count - 1; $i++) 
{
    Write-Host "Commit ID: $($response.value[$i].id)"
    Write-Host "Commit Message: $($response.value[$i].message)"
    Write-Host "Commit Author: $($response.value[$i].author.displayName)"
    Write-Host "------------------------------------------------------"
}

结果:

The associated commits to build 1999: 

Commit ID: c7d9318beda3950c1aa1b2c63f3a8ecf7
Commit Message: added platform x64
Commit Author: Shayki Abramczyk
------------------------------------------------------
Commit ID: e4a3e6cc4c118a9ffa936a5bf24b0c74
Commit Message: added check to verify tests
Commit Author: John Doe
------------------------------------------------------

如果要查看更多详细信息,可以使用Commits - Get Changes Rest API:

以上脚本得到了改进:

$buildId = 1999
$url = http://{tfsServer}:8080/tfs/{collection}/{teamProject}/_apis/build/builds/$($buildId)/changes?api-version=3.0

$response = Invoke-RestMethod -Uri $url -ContentType application/json -Method GET -UseDefaultCredentials

Write-Host "The associated commits to build $($buildId): `n"

For ($i=0; $i -le $response.count - 1; $i++) 
{
    Write-Host "Commit ID: $($response.value[$i].id)"
    Write-Host "Commit Message: $($response.value[$i].message)"
    Write-Host "Commit Author: $($response.value[$i].author.displayName)"
    Write-Host "------------------------------------------------------"

    $changesUrl = "http://{tfsServer}:8080/tfs/{collection}/{teamProject}/_apis/git/repositories/{repositoryId}/commits/$($response.value[$i].id)/changes?api-version=3.0"
    $changes = Invoke-RestMethod -Uri $changesUrl -ContentType application/json -Method GET -UseDefaultCredentials

    Write-Host Commits changes:
    For ($j=0; $j -le $changes.changeCounts.Edit; $j++) 
    {

    Write-Host $changes.changes[$j].item.path
    Write-Host $changes.changes[$j].changeType `n
    }

}

结果:

Associated commits to build 1999014: 

Commit ID: c7d9318beda3950c1aa1b2c63f3a8ecf74be26c3
Commit Message: added platform independent file separator
Commit Author: Kedar Kale
------------------------------------------------------
Commits changes:
/Server
edit 

/Server/parent/cognos2/package-cognos2/src/main/java/com/y/ModelController.java
edit 


Commit ID: e4a3e6cc4c118a9ffa936a5bf24b0c744b71b5b6
Commit Message: added check to verify BMT File Path for PathManipulation Fortify issue
Commit Author: Kedar Kale
------------------------------------------------------
Commits changes:

/Server/parent/cognos2
edit 

/Server/parent/cognos2/package-cognos2/src/main/java/com/y/ModelController.java
edit