您可以使用Azure PowerShell 任务来运行脚本以查找提交到存储库的新文件或修改后的文件,然后将它们复制到您的 blob 存储容器。以下是代码片段。
#get a list of all files that are part of the commit given SHA
$result=$(git diff-tree --no-commit-id --name-status -r $(Build.SourceVersion))
#The result looks like "M test/hello.txt A today.txt"
$array=$Result.Split(" ")
#The arraylooks like "
#M test/hello.txt
#A today.txt"
foreach ($ele in $array)
{
#Added (A), Copied (C), Deleted (D), Modified (M)
if ($ele.Contains("M") -eq 0 -Or $ele.Contains("A") -eq 0)
{
#filename looks like "test/hello.txt"
$fileName=$ele.Substring(2)
$sourcePath="$(Build.SourcesDirectory)" + "\" + $fileName
#your azcopy code here
}
}
另一个更简单的解决方法是,您可以使用PowerShell 任务找到提交到 repo 的新文件或修改后的文件,然后将它们复制到$(Build.SourcesDirectory)/temp
具有相应路径结构的新文件夹中,然后仍然使用Azure 文件复制任务复制文件夹下的$(Build.SourcesDirectory)/temp
文件到您的 Blob 存储容器。
# Write your PowerShell commands here.
Write-Host "Hello World"
$result=$(git diff-tree --no-commit-id --name-status -r $(Build.SourceVersion))
$array=$Result.Split(" ")
md $(Build.SourcesDirectory)/temp
foreach ($ele in $array)
{
if ($ele.Contains("M") -eq 0 -Or $ele.Contains("A") -eq 0)
{
$fileName=$ele.Substring(2)
$source="$(Build.SourcesDirectory)" + "\" + $fileName
$destination="$(Build.SourcesDirectory)/temp" + "\" + $fileName
New-Item $destination -type file -Force
Copy-Item -Path $source -Destination $destination
}
}
#Get-ChildItem -Path $(Build.SourcesDirectory)/temp –Recurse