Pas*_*ger 4 git tfsbuild git-lfs azure-devops
我有一个托管在VSTS上的存储库,包含一个通过git-lfs存储的文件.如果我只是让VSTS构建checkout存储库,它只需下载包含文件ID的git-lfs元数据文件.
以下是VSTS如何获取其来源的输出:
Syncing repository: MyRepo (Git)
Checking out c84ef2f2bbad4fa3dc70dbd4100534390b9c8f18 to d:\work\73\s
Checked out branch refs/heads/develop for repository MyRepo at commit c84ef2f2bbad4fa3dc70dbd4100534390b9c8f18
Run Code Online (Sandbox Code Playgroud)
我需要做什么来检查真实文件?
编辑:我假设我需要git lfs fetch在VSTS签出源后手动调用.但是在这种情况下如何处理身份验证(VSTS需要)?
更新
VSTS现在支持开箱即用的git LFS.这只是激活Repository / Checkout files from LFS构建定义中的选项的问题.它比下面的解决方案简单得多.
我尝试过Pascal的Enable Git Remote Access构建任务,但我无法使其工作.调用git-lfs.exe不会崩溃,但它不会将LFS文件转换为真实文件.
这是我如何使它工作.我首先必须Allow Scripts to Access OAuth Token在我的构建定义中启用该选项.然后我创建了一个PowerShell脚本来提取LFS依赖项:
# Inspired from here: http://ss64.com/ps/syntax-set-eol.html
function Set-UnixLineEndings([string]$file)
{
# Replace CR+LF with LF
$text = [IO.File]::ReadAllText($file) -replace "`r`n", "`n"
[IO.File]::WriteAllText($file, $text)
# Replace CR with LF
$text = [IO.File]::ReadAllText($file) -replace "`r", "`n"
[IO.File]::WriteAllText($file, $text)
}
if ((Test-Path env:SYSTEM_ACCESSTOKEN) -eq $false)
{
throw "OAuth token not available. Make sure that you select the option 'Allow Scripts to Access OAuth Token' in build 'Options' pane."
}
# git lfs needs the credentials of the git repository. When running
# under VSTS, these credentials are transfered to the git-lfs.exe
# application using the oauth token provided by VSTS. These
# credentials are stored in a file so that git lfs can find them.
$pwPath = Join-Path $PSScriptRoot pw.txt
$gitPwPath = $pwPath.Replace('\', '/') # Needs to be in unix format.
$repoUri = New-Object Uri $env:BUILD_REPOSITORY_URI
git config credential.helper "store --file=$gitPwPath"
@"
https://OAuth:$env:SYSTEM_ACCESSTOKEN@$($repoUri.Host)
"@ | Set-Content $pwPath
# Again, needs to be in unix format... sigh...
Set-UnixLineEndings -file $pwPath
& ".\git-lfs.exe" pull
if ($LASTEXITCODE -ne 0)
{
throw 'Failed to pull LFS files.'
}
Run Code Online (Sandbox Code Playgroud)
这显然假设您已在git存储库中存储了git-lfs.exe,并且LFS未跟踪此文件.