Azure DevOps single Repo下的多个构建管道在使用Git时会耗尽构建服务器内存
我在单个存储库下有20多个解决方案。即使我在触发器下添加了路径过滤器,每次构建管道签出都会将整个存储库保存在buildagents\u work/x/s文件夹下。它正在耗尽服务器内存。在这种情况下,任何人都可以帮助我为签出应用路径过滤器,或者每个构建管道都应该引用相同的源。我使用的是Git pipeline。注意:您还没有提供YAML文件供参考,因此做出一些标准假设,您使用的是一个简单的YAML模式 单一回购中的多个解决方案,因此是一个经典的单回购设置。你正在看这样的东西Azure DevOps single Repo下的多个构建管道在使用Git时会耗尽构建服务器内存,git,azure-devops,azure-pipelines,agent,build-server,Git,Azure Devops,Azure Pipelines,Agent,Build Server,我在单个存储库下有20多个解决方案。即使我在触发器下添加了路径过滤器,每次构建管道签出都会将整个存储库保存在buildagents\u work/x/s文件夹下。它正在耗尽服务器内存。在这种情况下,任何人都可以帮助我为签出应用路径过滤器,或者每个构建管道都应该引用相同的源。我使用的是Git pipeline。注意:您还没有提供YAML文件供参考,因此做出一些标准假设,您使用的是一个简单的YAML模式 单一回购中的多个解决方案,因此是一个经典的单回购设置。你正在看这样的东西 - script: n
- script: npm install
workingDirectory: service-b/
更改YAML中CICD管道代码开头的工作目录。一旦创建了工作目录,它的其余部分将与您现有的YAML一样进行
注意一些事情
- 可以根据特定的文件夹更改设置触发器。所以,如果你有
- 此外,对于部署,如果您是新手,我只需为每个项目构建一个新的管道,以简化部署
- 或者,如果您真的希望将所有内容都放在一个文件中,您可以添加条件并在单个YAML中路由整个mono repo。根据特定变量(例如,项目名称),可以将部署路由到所需的目标
- script: npm install
workingDirectory: service-b/
更改YAML中CICD管道代码开头的工作目录。一旦创建了工作目录,它的其余部分将与您现有的YAML一样进行
注意一些事情
- 可以根据特定的文件夹更改设置触发器。所以,如果你有
- 此外,对于部署,如果您是新手,我只需为每个项目构建一个新的管道,以简化部署
- 或者,如果您真的希望将所有内容都放在一个文件中,您可以添加条件并在单个YAML中路由整个mono repo。根据特定变量(例如,项目名称),可以将部署路由到所需的目标
cmd
或PowerShell
,以手动获取源代码。例如,仅获取测试文件夹中的目录src_1和src_2
parameters:
access: '{personal access token}'
repository: '{dev.azure.com/organisation/project/_git/repository}'
sourcePath: '{path/to/files/}'
- task: CmdLine@2
inputs:
script: |
ECHO ##[command] git init
git init
ECHO ##[command] git sparse-checkout: ${{ parameters.sourcePath }}
git config core.sparsecheckout true
echo ${{ parameters.sourcePath }} >> .git/info/sparse-checkout
ECHO ##[command] git remote add origin https://${{ parameters.repository }}
git remote add origin https://${{ parameters.access }}@${{ parameters.repository }}
ECHO ##[command] git fetch --progress --verbose --depth=1 origin master
git fetch --progress --verbose --depth=1 origin master
ECHO ##[command] git pull --progress --verbose origin master
git pull --progress --verbose origin master
在Azure DevOps中,我们没有只获取部分存储库的选项,但有一个解决方法:禁用“获取源”步骤,通过在脚本中手动执行相应的git命令,仅获取所需的源 a。禁用“获取源” b。在管道中添加任务
cmd
或PowerShell
,以手动获取源代码。例如,仅获取测试文件夹中的目录src_1和src_2
parameters:
access: '{personal access token}'
repository: '{dev.azure.com/organisation/project/_git/repository}'
sourcePath: '{path/to/files/}'
- task: CmdLine@2
inputs:
script: |
ECHO ##[command] git init
git init
ECHO ##[command] git sparse-checkout: ${{ parameters.sourcePath }}
git config core.sparsecheckout true
echo ${{ parameters.sourcePath }} >> .git/info/sparse-checkout
ECHO ##[command] git remote add origin https://${{ parameters.repository }}
git remote add origin https://${{ parameters.access }}@${{ parameters.repository }}
ECHO ##[command] git fetch --progress --verbose --depth=1 origin master
git fetch --progress --verbose --depth=1 origin master
ECHO ##[command] git pull --progress --verbose origin master
git pull --progress --verbose origin master
您可以参考本文了解更多详细信息假设使用内存,您指的是磁盘空间,我可以看到20个解决方案,每个解决方案都有自己的管道,每个解决方案都有自己的工作文件夹,这会导致它消耗大量磁盘空间。每个管道都有自己的工作区文件夹,这是为了允许它们独立地进行更改,同时也让它们以最快的速度进行更改。在您的情况下,每个管道访问相同的repo,但每个管道可能具有不同的repo设置。这样,代理就不必关心这个了 有一些选择,有些已经被其他人提到
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
条件的简单脚本步骤:always()
就可以了。这样,构建完成后,您就可以从驱动器中删除大型构建输出
- checkout: none
a工作树
。不是每次克隆repo,而是克隆一次,然后每个管道在$(build.sourcesdirectory)
中创建一个新的工作树。这可以节省大量的空间,同时保留构建代理上的所有历史记录,以便快速切换分支并支持gitversion之类的工具
b稀疏签出
此命令将允许您配置要在本地工作di中签出的文件夹
steps:
- ${{ if eq(parameters.experimentalTemplate, true) }}:
- template: experimental.yml
- ${{ if not(eq(parameters.experimentalTemplate, true)) }}:
- template: stable.yml