- script: |
git config --global http.extraHeader "AUTHORIZATION: bearer $(System.AccessToken)"
git clone --progress --verbose https://github.com/OrgName/RepoName.git "$(Build.ArtifactStagingDirectory)/Repo"
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$workingDirectory = "${{ '($(Build.SourcesDirectory))' :replace '\\', '\\\\' }}"
$maxPath = 260
Get-ChildItem -Path $workingDirectory -File -Recurse -ErrorAction SilentlyContinue | ForEach-Object {
if ($_.FullName.Length -gt $maxPath) {
$newPath = Join-Path -Path $(Agent.BuildDirectory) -ChildPath $_.Name
Copy-Item -Path $_.FullName -Destination $newPath -Force
Remove-Item -Path $_.FullName -Recurse -Force
Write-Output "$($_.FullName) has been truncated and moved to $newPath."
}
}
displayName: 'Truncate long paths'
使用第二种方法时,需要在build pipeline的任务列表中添加解决方案,并修改其路径以使用截断后的文件。