我在不同的存储库中有一个主要解决方案和 N 个其他解决方案。每次构建主解决方案时,我都必须构建 N 个其他解决方案并创建一个包含其他解决方案的主解决方案。我当前的构建管道看起来像这样。
[阶段1]
[工作1]构建主解决方案->发布管道工件(其他解决方案需要)[代理文件夹1]
[作业 2..N] 结帐解决方案“n”-> 构建 -> 发布管道工件 [代理文件夹 2..N]
- [第 2 阶段] - 在所有作业成功后
- [作业1] - 下载主工件-> 下载其他工件-> 将它们放在一个工件中-> 发布[代理文件夹N + 1]
我的问题是,下次运行此管道时,我的代理会回收最后一个文件夹,而其他文件夹会占用大量内存。有没有办法告诉管道在同一个代理工作目录中运行每个作业?或者重用创建的第一个目录(用于构建主要解决方案的目录)?
编辑:这是我的管道代码
resources:
repositories:
- repository: Repo.With.Templates
type: git
name: Repo.With.Templates
ref: feature/templates
- repository: Secondary.Repository.1
type: git
name: Secondary.Repository.1
ref: f/refactor/cd
- repository: Secondary.Repository.2
type: git
name: Secondary.Repository.2
ref: f/refactor/cd
trigger:
batch: true
branches:
include:
- 'f/core/cd-updates'
pool: 'Example pool'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
scriptSetBuildNumber: 'CI\SetBuildNumber.ps1'
nugetConfigFile: '$(Build.SourcesDirectory)/NuGet.config'
checkoutFolderRoot: '$(Build.SourcesDirectory)'
stages:
- stage: BuildingStage
jobs:
- job: Main_Solution_Build
steps:
- task: VSBuild@1
displayName: 'Build'
inputs:
solution: '$(solution)'
msbuildArgs: '
/p:DefineConstants="TESTENV"
/p:TreatWarningsAsErrors=true
/p:DeployDefaultTarget=WebPublish
/p:WebPublishMethod=FileSystem
/p:DeleteExistingFiles=True
/p:SkipInvalidConfigurations=false
/p:VisualStudioVersion=11.0
/p:publishUrl="$(Build.ArtifactStagingDirectory)\"
'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
# Zip bin folder and move to artifact folder
- task: ArchiveFiles@2
name: 'MovingMainSolutionBinToArtifacts'
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)/MainSolution/bin'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/Artifacts/MainSolution.zip'
replaceExistingArchive: true
- task: PublishPipelineArtifact@1
name: PublishMainSolutionBinPipeArtifact
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)\Artifacts\MainSolution.zip'
artifact: 'MainSolutionBinDrop'
publishLocation: 'pipeline'
- job: SecondarySolution1
dependsOn: Main_Solution_Build
steps:
- checkout: Secondary.Repository
- template: build-service-template.yml@Repo.With.Templates
parameters:
serviceName: "SecondarySolution1"
## Stage for assembling MainSolution and all the services together
- stage: Assemble
dependsOn: BuildingStage
jobs:
- job: AssembleArtifact
steps:
- checkout: none
- task: DownloadPipelineArtifact@2
name: "MainSolutionBinDrop"
inputs:
buildType: 'specific'
project: 'a12e0163-b207-400d-ac93-fa47964d5010'
definition: '2'
buildVersionToDownload: 'latest'
artifactName: 'MainSolutionBinDrop'
targetPath: '$(Build.ArtifactStagingDirectory)/MainSolutionBinDrop'
- task: DownloadBuildArtifacts@0
name: "DownloadServicesDrop"
inputs:
buildType: 'specific'
project: 'a12e0163-b207-400d-ac93-fa47964d5010'
pipeline: '2'
buildVersionToDownload: 'latest'
downloadType: 'single'
artifactName: 'ServicesDrop'
downloadPath: '$(Build.ArtifactStagingDirectory)'
# Tasks that produce one artifact out of Main artifact and all Secondary solution artifacts
# .....
# .....
# Publish
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/MainWithSecondary.zip'
artifact: 'MainWithSecondary'
publishLocation: 'pipeline'
以及用于构建N个二级解决方案的模板代码(本例中只有一个)
parameters:
- name: solution
type: string
default: '**/*.sln'
- name: buildPlatform
type: string
default: 'Any CPU'
- name: buildConfiguration
type: string
default: 'Release'
- name: nugetConfigFile
type: string
default: '$(Build.SourcesDirectory)/NuGet.config'
- name: serviceName
type: string
steps:
# Tasks that download main build artifact, build secondary solution and publishes secondary artifact
#
#
#Download main solution artifact
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'MainSolutionDrop'
targetPath: '$(Agent.BuildDirectory)/MainSolution'
- task: VSBuild@1
displayName: 'Build'
inputs:
solution: '$(solution)'
msbuildArgs: '
/p:TreatWarningsAsErrors=true
/p:DeployOnBuild=true
/p:SkipInvalidConfigurations=false'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
# Create artifact folder
- task: PowerShell@2
name: "CreateArtifactFolder"
inputs:
targetType: 'inline'
script: |
if (!(Test-Path "$(Build.ArtifactStagingDirectory)\${{ parameters.serviceName }}" -PathType Container)) {
New-Item -ItemType Directory -Path "$(Build.ArtifactStagingDirectory)\${{ parameters.serviceName }}"
}
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'ServicesDrop'
publishLocation: 'Container'