Only download changes to git repo in VSTS release pipeline

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-28 04:17:21

问题


I have a VSTS release pipeline that copies files from a git repo:

This git repo is really big - around 1GB in size. Every time I trigger a release, the VSTS agent downloads the entire contents of the git repo. Is there a way to configure VSTS to only download the changes to this git repo, i.e. run a git pull on the repository? This would save a lot of time and bandwidth.


回答1:


There are two ways can make the download artifacts step more efficient.

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

First delete the docker artifacts in the release pipeline. Then add PowerShell task instead (first task) at the beginning of each release environment.

And the PowerShell to download for the only changed files as below:

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
}

Note: you can use the PowerShell task version 2.*, since the Fail on Standard Error option is deselected by default.

Option 2: only download the latest commit from git repo

You can also specify the shallow fetch depth as 1, then the down artifact step will only download the latest commit. And it will reduce the artifact size sharply.




回答2:


You can remove the git repo from the "Artifacts" section on the release pipeline and get the repository in another way:

In your release, the first task will be Command Line task that pull the changes from the git repository.




回答3:


I think what you're looking for is really to use an artifact from a build pipeline. Here is the YAML for a build pipeline that publishes a README.md file as an artifact using the "Publish Artifact" task.

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

Then in a release pipeline you can add the artifact from your build pipeline (remember to build it at least once first!). This artifact will then be available in the release pipeline. Here's an example where I'm adding a Copy Files task to a pipeline and using the artifact;

So to summarise;

  • Configure a build pipeline that builds when the repo is updated so the latest files are always published as artifacts. The build pipeline will do the git pull you're looking for.
  • Consume those artifacts in your release pipeline.


来源:https://stackoverflow.com/questions/52280056/only-download-changes-to-git-repo-in-vsts-release-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!