我在单个存储库下有 20 多个解决方案。即使我在触发器下添加了路径过滤器,每个构建管道 checkout 也会将整个存储库保存在构建代理 _work/x/s 文件夹下。它正在耗尽服务器内存。在这种情况下,任何人都可以帮助我应用路径过滤器进行 checkout ,或者每个构建管道应该引用相同的源。我正在使用 Git 管道。
最佳答案
假设内存,你指的是磁盘空间,我可以看到20个解决方案,有自己的管道,每个都有自己的工作文件夹,会导致它消耗大量磁盘空间。每个管道都有自己的工作区文件夹,这是为了允许它们独立更改,但给它们最大的速度。在您的情况下,每个管道访问相同的存储库,但每个管道可能具有不同的存储库设置。这样代理就不必关心这个。
有几个选项,其中一些已经被其他人提到过。
使用浅克隆。 You can configure the pipeline to only fetch up to X amount of commits of history 。这可能会大大减少每个管道的工作文件夹大小,但如果您构建许多不同的分支,则可能会稍微减慢构建速度。您可以通过将 fetchDepth 设置为较小的数字来启用浅克隆。如果您依赖 GitVersion 来计算内部版本号,或者依赖于存储库历史记录的任何其他任务,则当 fetchDepth 设置得太低时,它们可能会中断。
steps: - checkout: self | none | repository name # self represents the repo where the initial Pipelines YAML file was found clean: boolean # if true, run `execute git clean -ffdx && git reset --hard HEAD` before fetching fetchDepth: number # the depth of commits to ask Git to fetch; defaults to no limit lfs: boolean # whether to download Git-LFS files; defaults to false submodules: true | recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules; defaults to not checking out submodules path: string # path to check out source code, relative to the agent's build directory (e.g. \_work\1); defaults to a directory called `s` persistCredentials: boolean # if 'true', leave the OAuth token in the Git config after the initial fetch; defaults to false
在每次构建结束时进行清理。您可以在管道末尾添加一个脚本步骤来清理本地工作文件夹。一个带有
condition:always()
的简单脚本步骤应该可以解决问题。这样,您可以在构建完成后从驱动器中删除大量构建输出。 You could use a YAML template to auto-inject this task into every job/pipeline .控制 checkout 流程 正如其他人提到的,您可以告诉 Pipelines 不要 checkout 存储库,这样您就可以自己控制该流程。您在这里有几个选择:
- checkout: none
a.
工作树
,this command will allow your build pipelines to share their.git
folder 。您不必每次都克隆存储库,而是克隆一次,然后每个管道都会在$(build.sourcesdirectory)
中创建一个新的工作树。这可以节省大量空间,同时保留构建代理上的所有历史记录,以实现快速分支切换并支持 gitversion 等工具。 Follow the general steps from Vitu Liu .b.
sparse-checkout
此命令将允许您配置要在本地工作目录中 check out 哪些文件夹。 git 命令行客户端非常聪明,还可以仅获取这些文件夹所需的数据。 Follow the steps from Vitu Liu .c.使用自定义 checkout 任务。 This custom checkout task will use a single folder on the agent and uses a symlink to make sure each pipeline uses the same repo under the hood 。但它似乎没有发布到市场,因此如果使用 tfx-cli,则必须安装。
cd drive:\path\to\extracted\zip tfx login tfx build tasks upload --task-path .
创建单个管道并包含参数化 YAML 文件。通过创建单个管道,代理将创建单个工作文件夹。然后,根据更改的文件,执行要构建的解决方案的管道文件。 See the Parameters to select at runtime docs 。其他答案已经解释了如何 use the git command line to iterate the files that have changed and setting a variable based on their outcome .
steps: - ${{ if eq(parameters.experimentalTemplate, true) }}: - template: experimental.yml - ${{ if not(eq(parameters.experimentalTemplate, true)) }}: - template: stable.yml
使用新的规模设定代理。 Azure Pipelines now offers a way to setup your own agent in the same way the hosted pipelines run 。优点之一是您可以控制何时重置图像。基本上允许您在每次构建时都拥有一个干净的镜像,并预安装所有依赖项或预填充 npm/nuget 缓存。低成本并行化功能可能对您的场景也非常有用。
配置维护,您可以在代理池上启用清理作业。它会排队一个特殊的作业来清理工作文件夹、旧任务、临时文件等。如果不是所有 20 个解决方案都在同一天运行,它可能会有所帮助。您可以在帐户级别找到此选项。
关于git - Azure DevOps 单个 Repo 下的多个构建管道 使用 Git 时耗尽构建服务器内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64085665/