获取 VSTS 的 git 存储库中上次更新/提交的文件



我正在尝试增量部署 Azure 数据工厂的管道。换句话说,我计划仅将最近修改的管道或最近添加的管道部署到 Azure 门户中的 ADF。目前,我在 CD 管道中使用 powershell 任务来部署所有管道。如何使用时间戳获取最近修改的管道?任何建议都会有所帮助。:)

如果要生成所有文件,但仅推送/发布要部署的修改文件,这是可能的。

可以使用 PowerShell 任务获取$(Build.SourcesDirectory)中的最后一个提交 ID(sha-1 值(,然后使用git show <commit id>查找提交中更改的文件,然后将这些文件复制到$(build.artifactstagingdirectory)。最后将这些文件发布到服务器。

您可以使用 REST API 获取更改的文件。

简单的Powershell脚本:

Param(
[string]$collection,
[string]$project,
[string]$repository,
[string]$commit,
[string]$token
)
$u="$($collection)$($project)/_apis/git/repositories/$repository/commits/$commit/changes"
Write-Output $u
$changedFiles=New-Object System.Collections.ArrayList
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$token)))
$result=Invoke-RestMethod -Method Get -Uri $u -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType "application/json"
Foreach($c in $result.changes)
{
If($c.item.isFolder -ne 'true')
{
Write-Output $c.item.path
$changedFiles.Add(($c.item.path))
}
}

参数(选中生成/发布定义中的"允许脚本访问 OAuth 令牌"选项(:

-collection $(System.TeamFoundationCollectionUri) -project $(System.TeamProject) -repository $(Build.Repository.Name) -commit $(Build.SourceVersion) -token $(System.AccessToken)

最新更新