仅在 VSTS 发布管道中下载对 git 存储库的更改

Only download changes to git repo in VSTS release pipeline

我有一个 VSTS 发布管道,它从 git 存储库复制文件:

这个 git 存储库非常大 - 大约 1GB。每次触发发布时,VSTS 代理都会下载 git 存储库的全部内容。有没有办法将 VSTS 配置为仅将 更改 下载到此 git 存储库,即存储库上的 运行 a git pull?这将节省大量时间和带宽。

我认为您真正想要的是使用构建管道中的 工件。这是构建管道的 YAML,它使用 "Publish Artifact" 任务将 README.md 文件发布为 artifact

resources:
- repo: self
queue:
  name: Hosted VS2017
steps:
- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
  inputs:
    PathtoPublish: README.md

然后在发布管道中,您可以从构建管道添加工件(请记住至少先构建一次!)。然后,该工件将在发布管道中可用。这是一个示例,我将复制文件任务添加到管道并使用工件;

总结一下;

  • 配置在更新存储库时构建的构建管道,以便始终将最新文件发布为工件。构建管道将完成您正在寻找的 git pull
  • 在您的发布管道中使用这些工件。

您可以从发布管道的 "Artifacts" 部分删除 git 存储库并以另一种方式获取存储库:

在您的版本中,第一个任务是从 git 存储库中拉取更改的命令行任务。

有两种方法可以使下载工件的步骤更高效。

选项 1:使用 PowerShell 任务下载最新提交中的更新文件

首先删除发布管道中的 docker 个工件。然后在每个发布环境的开头添加 PowerShell 任务(第一个任务)。

以及为唯一更改的文件下载的 PowerShell,如下所示:

mkdir partrepo
cd partrepo
git init
git remote add up -f https://Personal%20Access%20Token:{PAT}@{account}.visualstudio.com/{project}/_git/{repo}
#Or you can use the new Azure devops url instead
$files=$(git diff up/master up/master~ --name-only)
echo "changed files: $files"
$t=$files -is [array]
if ($files -is [array])
{
  echo "multiple files updated"
  for ($i=0;$i -lt $files.Length; $i++)
  {
  $tfile=$files[$i]
  git checkout up/master -- $tfile
  }
}
else
{
  git checkout up/master -- $files
}

注意:您可以使用 PowerShell 任务版本 2.*,因为默认情况下取消选择标准错误时失败选项。

选项 2:仅从 git 存储库下载最新的提交

你也可以指定shallow fetch depth为1,那么down artifact步骤只会下载最新的commit。而且它会大大减小工件的大小。