I have a main solution and N other solutions in different repositories. Each time main solution builds I have to build N others and create an artifact of main solution containing others. My current build pipeline looks like this.
[Stage 1]
[Job 1] Build Main solution -> publish pipeline artifact (needed for other solutions) [agent folder 1]
[Job 2..N] Checkout Solution "n" -> build -> publish pipeline artifact [agent folders 2..N]
- [Stage 2] - After all jobs succeded
- [Job 1] - Download main artifact -> download other artifacts -> put them in one artifact -> publish [Agent folder N + 1]
My problem is that next time this pipeline runs, my agent recycles the last folder and the others are there waisting a lot of memory. Is there a way to tell the pipeline to run each job in the same agent working directory? Or to reuse the first directory created (the one for building main solution)?
EDIT: Here is the code of my pipeline
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'
And the code of the template used to build N secondary solutions (in this example only one)
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'