如何在 TFS Build (Git) 中单独获取修改过的文件 [英] How to get modified files alone in TFS Build (Git)

查看:33
本文介绍了如何在 TFS Build (Git) 中单独获取修改过的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的 TFS 构建获取源任务中单独获取修改后的/新文件.

到目前为止我发现我们可以通过定义

Shallow Fetch:允许您仅下载存储库的最新快照.下载速度会快很多,但可能会导致 GitVersion 等工具失败(它依赖历史数据来计算版本号).

Clean: False:将保留先前构建的内容,允许您对源进行增量获取,使用支持它的工具进行增量构建.您可以将 Clean:False 与执行更有针对性的清理的自定义步骤结合起来.

如果您需要更改的文件,您可以发出 git 命令从同步的 git 存储库中复制它们.请参阅:https://stackoverflow.com/a/4126342/736079.

或者,不要同步源并在 Powershell 中使用基于自定义 VSTS Git REST API 的脚本来获取您想要的确切文件.请参阅:https://docs.microsoft.com/en-us/rest/api/vsts/git/items?view=vsts-rest-4.1.

I needed to get the modified/new files alone in my TFS build get source task.

So far I've found We can disable the Get Source task by defining the variable Build.SyncSources = false

This will Just ignore of getting all the sources, which will eventually make my CopyFile Task to Fail since it using the $(Build.SourcesDirectory) as the source

> 2018-07-28T03:13:46.5709194Z Task         : 
> Copy Files 2018-07-28T03:13:46.5709194Z Description  : Copy files from source
> folder to target folder using match patterns (The match patterns will
> only match file paths, not folder paths) 2018-07-28T03:13:46.5709194Z
> Version      : 2.117.0 2018-07-28T03:13:46.5709194Z Author       :
> Microsoft Corporation 2018-07-28T03:13:46.5709194Z Help         :
> [More Information](https://go.microsoft.com/fwlink/?LinkID=708389)
> 2018-07-28T03:13:46.5709194Z
>     ============================================================================== 2018-07-28T03:13:47.1855024Z ##[error]Unhandled: Not found
> SourceFolder: $(Build.SourcesDirectory)

The Question in my Git Source Control there are many files which I don't want all to fetch while Building, Instead of that the files which are modified on that commit/PR merge I need to fetch.

How can I achieve this?

解决方案

Once a build server has synced the Git repository it will be able to just fetch the differences between the last build. Since Git relies on the full repository state being present (a commit is a pointer to a state of the working folder which includes all files at that state), it's not possible to just grab the changed files.

There is a switch in the Agent Phase step which controls whether the working directory will be cleaned, in which case the agent will have to sync the whole git repo. There's also an option there to only fetch the latest snapshot, instead of the full history:

Shallow Fetch: Allows you to download only the latest snapshot of the repository. Will download much faster, but may cause tools like GitVersion to fail (it relies on the history data to calculate a version number).

Clean: False: will retain the contents of the previous build allowing you to do incremental fetches of sources, incremental builds with tools that support it. You can combine Clean:False with a custom step which performs more targeted clean up.

If you need the changed files you can issue a git command to copy them from your synced git repo. See: https://stackoverflow.com/a/4126342/736079.

Alternatively, don't sync the sources and use a custom VSTS Git REST API based script in Powershell to fetch the exact files you're after. See: https://docs.microsoft.com/en-us/rest/api/vsts/git/items?view=vsts-rest-4.1.

这篇关于如何在 TFS Build (Git) 中单独获取修改过的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆