仅在VSTS版本管道中下载对git repo的更改

问题描述 投票:1回答:3

我有一个VSTS发布管道从git仓库复制文件:

enter image description here

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

git azure-devops azure-pipelines azure-pipelines-release-pipeline
3个回答
4
投票

有两种方法可以使下载工件更有效。

Option 1: use PowerShell task to download the updated files in the latest commit

首先删除发布管道中的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.*,因为默认情况下取消选中“标准错误时失败”选项。

Option 2: only download the latest commit from git repo

您还可以将浅提取深度指定为1,然后向下工件步骤将仅下载最新提交。它会大幅减少人工制品的尺寸。

enter image description here


1
投票

您可以从发布管道上的“工件”部分中删除git repo,并以另一种方式获取存储库:

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

enter image description here


0
投票

我认为您正在寻找的是真正使用构建管道中的工件。以下是构建管道的YAML,它使用“发布工件”任务将README.md文件发布为artifact

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

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

enter image description here

总结一下;

  • 配置在更新repo时构建的构建管道,以便最新文件始终作为工件发布。构建管道将执行您正在寻找的git pull
  • 在发布管道中使用这些工件。
© www.soinside.com 2019 - 2024. All rights reserved.