对所选文件使用AzureFileCopy任务

对所选文件使用AzureFileCopy任务,azure,azure-devops,blob,azure-blob-storage,azure-file-copy,Azure,Azure Devops,Blob,Azure Blob Storage,Azure File Copy,我在Azure DevOps中有一个非常简单的管道。当提交到开发分支时,将签出repo中的文件,然后使用AzureFileCopy任务将其推送到blob存储容器中。当我当前运行管道时,blob中的所有文件都显示了一个修改日期,包括已经在repo中的文件 我们的开发人员询问我们是否可以更改它,以便只更新提交给回购协议的新文件或修改后的文件,而不覆盖所有其他文件。我已经尝试使用overwrite参数设置为false,但这会忽略对文件内容的任何更改 我已经考虑过改用powershell,但正在寻找最佳

我在Azure DevOps中有一个非常简单的管道。当提交到开发分支时,将签出repo中的文件,然后使用AzureFileCopy任务将其推送到blob存储容器中。当我当前运行管道时,blob中的所有文件都显示了一个修改日期,包括已经在repo中的文件

我们的开发人员询问我们是否可以更改它,以便只更新提交给回购协议的新文件或修改后的文件,而不覆盖所有其他文件。我已经尝试使用overwrite参数设置为false,但这会忽略对文件内容的任何更改

我已经考虑过改用powershell,但正在寻找最佳方法的建议?

您可以使用运行脚本来查找提交到repo的新文件或修改后的文件,然后将它们复制到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
        
    }
}
另一个更简单的解决方法是,您可以使用查找提交到repo的新文件或修改后的文件,然后将它们复制到具有相应路径结构的新
$(Build.SourcesDirectory)/temp
文件夹中,然后仍然使用复制
$(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


谢谢Edward,这真的很有帮助,使用第二种方法就可以工作了。:)