How to get modified files alone in TFS Build (Git)

谁说我不能喝 提交于 2020-01-05 04:28:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/51567768/how-to-get-modified-files-alone-in-tfs-build-git

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