Reputation: 7744
I have a relatively simple YAML pipeline below for doing the following.
Restore any dependencies
Build any projects
Run any tests
Publish the results
This is split across multiple stages that have multiple jobs.
The issue is that the jobs do not seem to be aware of the previous jobs. This is making the steps take longer to complete and / or have unexpected results. For example the publish artifacts does not publish anything as it has no artifacts from the previous jobs to publish.
How do I make the stages and jobs are of previous actions so that the pipeline works as expected?
trigger:
- master
stages:
- stage: RestoreDependancies
jobs:
- job: RestoreNuGetPackages
pool:
vmImage: 'windows-latest'
steps:
- task: NuGetToolInstaller@1
displayName: 'Install NuGet'
inputs:
versionSpec:
checkLatest: true
- task: NuGetCommand@2
displayName: 'Restore NuGet'
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
- stage: Build
dependsOn: RestoreDependancies
jobs:
- job: BuildVisualStudioProjects
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI@2
displayName: 'Build Projects'
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration "Release"'
- stage: Test
dependsOn: Build
jobs:
- job: TestVisualStudioProjects
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI@2
displayName: 'Run all Unit Tests'
inputs:
command: 'test'
projects: '**/*Tests/*.csproj'
arguments: '--configuration "Release" --collect "Code coverage"'
- stage: Publish
dependsOn:
- Build
- Test
jobs:
- job: PublishTestResults
pool:
vmImage: 'windows-latest'
steps:
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'XUnit'
testResultsFiles: '**/TEST-*.xml'
failTaskOnFailedTests: true
buildConfiguration: 'Release'
- job: PublishArtifacts
pool:
vmImage: 'windows-latest'
steps:
- task: CopyFiles@2
displayName: 'Copy Artifacts'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**\bin\**' # Contents: '**\bin\Release\**'
TargetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
Upvotes: 0
Views: 191
Reputation: 41755
Stages not intended to Restore/Build/Test/Publish Artifacts, all those steps should be in one stage with one job and multiple steps.
Each stage it's a new fresh agent and the agent download again the code, this is the reason why it takes a lot of time and has no artifacts to publish, each stage not know the other stages (by default).
So when you want a new stage? for running functional test or deploy your app, for example.
Upvotes: 2