I'm new to Azure DevOps pipelines. I would like to run several jobs building the solutions. The solutions need to be run in specific order that is why I do not want to run them in one task. I don't want to have all the projects in single solution because there are a lot of them. A single job builds the solution and runs the unit tests:
- job: 'SolutionN_build'
displayName: 'SolutionN: build & test'
steps:
- task: DotNetCoreCLI@2
displayName: 'Build: dotnet build $(buildConfiguration)'
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration) -p:FileVersion=$(fileVersion) -p:Version=$(version)'
projects: '$(solution1Path)\SolutionN.sln'
- task: VSTest@2
enabled: true
displayName: 'Run unit tests: vstest.console.exe'
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
vstestLocationMethod: 'location'
vstestLocation: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe'
In the Directory.Build.props file I have a post build event defined that copies the produced dlls to a separate folder. The problem is the dlls produced in job for Solution1 are not accessible in job for building Solution2.
Are the jobs isolated and the dlls would not be visible between them? Is there any parameters I can set? Or maybe there is a way to configure the order of building the solutions in single task?
Are the jobs isolated and the dlls would not be visible between them?
That's correct, each job might be run by a different build agent. Agents might run in different VMs or containers.
The problem is the dlls produced in job for Solution1 are not accessible in job for building Solution2.
If you need to share files between jobs consider using pipeline artifacts:
Sample pipeline contains 2 jobs:
build
: creates, builds and publishes .NET projects as artifacts.test
: downloads the artifacts and runs unit tests using the DLLs.jobs:
- job: build
displayName: 'Build'
steps:
- checkout: none
- task: UseDotNet@2
inputs:
version: '8.x'
- script: |
dotnet new console -n MyApp --force
dotnet new nunit -n MyApp.Tests --force
displayName: 'Create sample .NET projects'
workingDirectory: $(System.DefaultWorkingDirectory)
- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: 'publish'
publishWebProjects: false
zipAfterPublish: false
modifyOutputPath: true
projects: '$(System.DefaultWorkingDirectory)/**/*.csproj'
arguments: --output $(Build.ArtifactStagingDirectory)
- task: PublishPipelineArtifact@1
displayName: 'Publish artifact'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: 'app'
publishLocation: 'pipeline'
- job: test
displayName: 'Test'
dependsOn: build
steps:
- checkout: none
- task: DownloadPipelineArtifact@2
displayName: 'Download artifact'
inputs:
buildType: 'current'
artifact: app
targetPath: '$(Pipeline.Workspace)'
- task: UseDotNet@2
inputs:
version: '8.x'
- task: DotNetCoreCLI@2
displayName: 'dotnet test'
inputs:
command: 'test'
projects: '$(Pipeline.Workspace)/**/MyApp.Tests.dll'