【发布时间】:2019-02-13 09:26:35
【问题描述】:
我已按照solution 获取文件,这些文件在上次提交中被修改。
解决方案会像
$files=$(git diff HEAD HEAD~ --name-only)
echo $files
$temp=$files -split ' '
$count=$temp.Length
echo "Total changed $count files"
New-Item -ItemType directory -Path $(Build.ArtifactStagingDirectory)\files
For ($i=0; $i -lt $temp.Length; $i++)
{
$name=$temp[$i]
echo "this is $name file"
if (Test-Path "$(Build.SourcesDirectory)\$name")
{
Copy-Item $(Build.SourcesDirectory)\$name $(Build.ArtifactStagingDirectory)\files
}
}
有了这个,我可以从上次提交中获取修改后的文件,但在我的情况下,可能有 N 次新的提交。
所以我看到了一种通过更改 cmd 来实现这一点的方法
2 次提交
$files=$(git diff HEAD HEAD~2 --name-only)
3 次提交
$files=$(git diff HEAD HEAD~3 --name-only)
像这样,
但是,我无法找到一种方法来获取构建定义中新提交的数量
更新 1
我的 TFS Get Sources 总是用最新的提交 id 签出相应的分支
2018-09-08T06:05:35.8623084Z ##[command]git checkout --progress --force e88c5a4bf29a539c515ca0e5fea104799426026e
2018-09-08T06:05:36.3681977Z Previous HEAD position was 40ac471... Updated xxxxxxx
这也使得找到旧的提交 ID 变得困难
【问题讨论】: