staging and prod skipped - azure

entire pipeline was run successfully but why staging and prod were skipped ?
I have completed all the steps in Azure pipelines but it wan't completed staging and prod. I want to know that why those are skipping
azure-pipelines.yml
branches:
include:
- master
pool:
name: CharanAgentPool
variables:
- name: buildConfiguration
value: Release
stages:
- stage: Build
displayName: ApplicationBuild
jobs:
- job: Build
variables:
- name: continueOnError
value: false
steps:
- task: DotNetCoreCLI#2
inputs:
command: restore
projects: '**/*.csproj'
- task: VSBuild#1
inputs:
solution: '**\*.sln'
msbuildArgs: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"
configuration: release
clean: true
restoreNugetPackages: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: $(Build.ArtifactStagingDirectory)
ArtifactName: drop
publishLocation: Container
- stage: Test
displayName: UnitTest
jobs:
- job: Test
steps:
- task: VSTest#2
inputs:
testSelector: testAssemblies
testAssemblyVer2: >
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: $(System.DefaultWorkingDirectory)
- stage: SonarQube
displayName: StaticCodeAnalysis
jobs:
- job: SonarQube
steps:
- task: CmdLine#2
inputs:
script: echo "code analysis"
- stage: deploy_dev
displayName: ApplicationDeplo
jobs:
- job: dev
steps:
- task: DownloadBuildArtifacts#0
inputs:
buildType: current
downloadType: single
artifactName: drop
downloadPath: $(System.DefaultWorkingDirectory)
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: AzureRM
azureSubscription: '$(connectedservicename)'
appType: webApp
WebAppName: '$(app_name)'
packageForLinux: $(System.DefaultWorkingDirectory)/drop/*.zip
- stage: functionaltest_dev
displayName: FunctionalTest
jobs:
- job: FunctionalTesting
steps:
- task: CmdLine#2
inputs:
script: echo "function testing"
- stage: deploy_staging
displayName: staging
jobs:
- job: staging
condition: and(succeeded(), eq(variables['deploy_staging'], 'yes'))
steps:
- task: DownloadBuildArtifacts#0
inputs:
buildType: current
downloadType: single
artifactName: drop
downloadPath: $(System.DefaultWorkingDirectory)
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: AzureRM
azureSubscription: '$(connectedservicename)'
appType: webApp
WebAppName: $(staging_app)
packageForLinux: $(System.DefaultWorkingDirectory)/drop/*.zip
- stage: functionaltest_staging
displayName: FunctionalTestStaging
jobs:
- job: FunctionalTesting
steps:
- task: CmdLine#2
inputs:
script: echo "function testing"
- stage: deploy_prod
displayName: DeployToProd
jobs:
- job: prod
condition: and(succeeded(), eq(variables['deploy_prod'], 'yes'))
steps:
- task: DownloadBuildArtifacts#0
inputs:
buildType: current
downloadType: single
artifactName: drop
downloadPath: $(System.DefaultWorkingDirectory)
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: AzureRM
azureSubscription: '$(connectedservicename)'
appType: webApp
WebAppName: $(prod_app)
packageForLinux: $(System.DefaultWorkingDirectory)/drop/*.zip
- stage: functionaltest_prod
displayName: FunctionalTestingProd
jobs:
- job: FunctionalTesting
steps:
- task: CmdLine#2
inputs:
script: echo "function testing"
entire pipeline was run successfully but why staging and prod were skipped ?

- job: staging
condition: and(succeeded(), eq(variables['deploy_staging'], 'yes'))
This chunk of pipeline controlls when job will run. Condition which you set checks if steps before ended succesfully and if variable deploy_staging is set to yes.
You never set the variable to yes so this job won't run.

Related

how to use Devops Pipelines and Releases: Deploying One solution with 6 webjob console app as one zip file/package

My situation : I have 1 solution with 6 console apps.
My target : publish 6 console apps as 6 web jobs under 1 App service.
Summary :
6 consoleapps -->convert --> 6 dlls in 1 ZIP file --> Publish --> 6 webjobs in 1 App Service
How can I do that in Yaml?
azure-pipeline.yaml :
trigger:
- main
variables:
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
stages:
- stage: Build
displayName: 'Build stage'
pool:
vmImage: 'windows-latest'
jobs:
- job: BuildOrderShipmentJob
displayName: 'Build Order Shipment Job'
steps:
- checkout: self
displayName: 'checkout'
- task: NuGetToolInstaller#0
displayName: "NuGet use 6.3.0"
inputs:
versionSpec: 6.3.0
- task: NuGetCommand#2
displayName: 'nuget restore'
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
- task: MSBuild#1
displayName: 'msbuild'
inputs:
solution: 'src/xxxxx/xxxxx.csproj'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
msbuildArguments: '/p:OutputPath=$(build.ArtifactStagingDirectory)/xxxxx-$(Build.BuildNumber)/App_Data/jobs/continuous/xxxxx'
- task: ArchiveFiles#2
displayName: 'package'
inputs:
rootFolderOrFile: '$(build.ArtifactStagingDirectory)/xxxxx-$(Build.BuildNumber)'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/xxxxx-$(Build.BuildNumber).zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
displayName: 'publish'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/xxxxx-$(Build.BuildNumber).zip'
ArtifactName: 'drop'
- stage: Test
displayName: 'Test stage'
pool:
vmImage: 'windows-latest'
jobs:
- job: TestOrderShipmentJob
displayName: 'Test Order Shipment Job'
steps:
- checkout: self
displayName: 'checkout'
- task: NuGetToolInstaller#0
displayName: "NuGet use 6.3.0"
inputs:
versionSpec: 6.3.0
- task: NuGetCommand#2
displayName: 'nuget restore'
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
- task: VSBuild#1
displayName: 'vsbuild'
inputs:
solution: '**/*.sln'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
clean: true
- task: DotNetCoreCLI#2
displayName: 'dotnet test'
inputs:
command: test
arguments: '--collect:"XPlat Code Coverage" /p:CoverletOutputFormat=cobertura'
publishTestResults: true
workingDirectory: '$(System.DefaultWorkingDirectory)/src'
- task: PublishCodeCoverageResults#1
displayName: 'publish code coverage results'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
- stage: Deploy_Test
displayName: 'Deploy test'
dependsOn: Test
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
pool:
name: 'bmersgtsteuw-app-eurotracs-pool'
jobs:
- deployment: BaukingOrderShipmentJob
displayName: 'Deploy Order Shipment Job'
environment: 'BME-CF-Test'
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: drop
- task: AzureRMWebAppDeployment#4
inputs:
ConnectionType: AzureRM
azureSubscription: 'ARM-Con-BME-SUB-TST-EUW-APP'
appType: 'webApp'
WebAppName: 'xxxapptsteuw-app-tst'
package: '$(Pipeline.Workspace)/drop/xxxxx-$(Build.BuildNumber).zip'
removeAdditionalFilesFlag: true
- stage: Deploy_Prod
displayName: 'Deploy production'
dependsOn: Deploy_Test
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
pool:
name: 'xxxrsgprdeuw-app-tst-pool'
jobs:
- deployment: YYYYYOrderShipmentJob
displayName: 'Deploy Order Shipment Job'
environment: XXXX-CF-Prod
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: drop
- task: AzureRMWebAppDeployment#4
inputs:
ConnectionType: AzureRM
azureSubscription: 'ARM-Con-XXXX-SUB-PRD-EUW-APP'
appType: 'webApp'
WebAppName: 'xxxappprdeuw-app-tst'
package: '$(Pipeline.Workspace)/drop/xxxxx-$(Build.BuildNumber).zip'
removeAdditionalFilesFlag: true
Based on your situation, you have 1 solution with 6 console apps.
6 consoleapps -->convert --> 6 dlls in 1 ZIP file --> Publish --> 6 webjobs in 1 App Service
To achieve your requirement, you can directly define the solution file and modify the msbuildArguments in Msbuild task.
For example:
- task: MSBuild#1
displayName: 'Build solution **/*.sln'
inputs:
solution: '**/*.sln'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
msbuildArguments: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
Then the 6 console apps in 1 solution file will be built and the output will be saved at one zip file. So you can remove the ArchiveFiles task in YAML sample

CI-CD Azure devops for function app deployment

My Function app Name:
my_func_dev_app
Functions I have in my project
func_dev
func_prd
Push func_dev to my_func_dev_app
Push func_prd to my_func_prd_app
But It is pushing both func_dev and func_prd to my_func_de_app
My app folder structure
(folder)myapp_function
(folder)func_dev --__init__.py
-- function.json
(folder)func_prd --__init__.py
-- function.json
task.py
Multi stage Pipeline:
#pipelines1
trigger:
- '*'
stages:
- stage: 'Build'
displayName: 'Build the web application'
jobs:
- job: 'Build'
displayName: 'Build job'
pool:
name: 'onprem_agent'
steps:
- task: CopyFiles#2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: |
**/*
!.git/**
OverWrite: true
CleanTargetFolder: true
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: ArchiveFiles#2
displayName: "Archive files"
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/myapp_function'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/build$(Build.BuildId).zip'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'myapp_function'
- stage: 'DEV_AZURE'
displayName: 'Az DEV Deploy'
dependsOn: Build
condition: |
and
(
succeeded(),
eq(variables['Build.SourceBranchName'], variables['releaseBranchName'])
)
jobs:
- deployment: Deploy
environment: dev
variables:
- group: Release
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: myapp_function
displayName: Downloading artifacts
- task: AzureFunctionApp#1
inputs:
azureSubscription: CI-CD
appType: functionAppLinux
appName: my_func_dev_app
package: '$(Pipeline.Workspace)/myapp_function/*.zip'
deployToSlotOrASE: true
resourceGroupName: my-rg
slotName: PRODUCTION
displayName: 'Deploying dev'
How to fix? Push func_dev to my_func_dev_app and ignore func_prd
How to fix? Push func_dev to my_func_dev_app and ignore func_prd
To solve this issue, you can package your two projects separately into zip.
In your ArchiveFiles task, you need to specify a specific project.
For example:
For func_dev project: $(Build.ArtifactStagingDirectory)/myapp_function/func_dev
- task: ArchiveFiles#2
displayName: "Archive files"
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/myapp_function/func_dev'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/build$(Build.BuildId)-func_dev.zip'
Then you can only package the project corresponding to the function app name.
If you want to deploy two projects to the corresponding function app in one pipeline at the same time, you could use the same method to separately package the two projects as zip.

Extra Artifact published when using templates

Currently started using global templates in the majority of my pipelines and there is an issue occurring where an empty artifact is getting published in addition to the original artifact.
This is causing minor issues with some of my deployment groups (workaround is to just ignore it when downloading). While it is not causing major issues, I'm just curious about why the extra file is being published as well as preventing it.
EDIT:
Included my yaml template being used as:
parameters:
ArtifactPath: ''
ArtifactName: ''
ArtifactPublish: false
Artifacts: []
Solution: '**/*.sln'
jobs:
- job: Build
displayName: 'Build, Pack, and Publish'
pool:
vmImage: 'windows-latest'
variables:
solution: ${{ parameters.Solution }}
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
prereleaseVersion: '$(majorVersion).$(minorVersion).$(Build.BuildNumber)-$(Build.SourceBranchName)'
releaseVersion: '$(majorVersion).$(minorVersion).$(Build.BuildNumber)'
steps:
- task: NuGetToolInstaller#1
displayName: "Install Nuget Tool"
- task: NuGetCommand#2
displayName: 'Restore Nuget Packages'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'select'
vstsFeed: 'FEED'
- task: VSBuild#1
displayName: 'Build Solution'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
displayName: 'Run Unit Tests'
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: NuGetCommand#2
displayName: 'Pack Prerelease Nuget Packages'
condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/master'), ne(variables['Build.SourceBranch'], 'refs/heads/release'))
inputs:
command: 'pack'
configuration: '$(buildConfiguration)'
packagesToPack: '**/nuspec/*.nuspec'
versioningScheme: 'byEnvVar'
versionEnvVar: prereleaseVersion
verbosityPack: 'detailed'
- task: NuGetCommand#2
displayName: 'Push Prerelease Nuget Packages'
condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/master'), ne(variables['Build.SourceBranch'], 'refs/heads/release'))
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'FEED'
verbosityPush: 'normal'
- task: NuGetCommand#2
displayName: 'Pack Release Nuget Packages'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/release'))
inputs:
command: 'pack'
configuration: '$(buildConfiguration)'
packagesToPack: '**/nuspec/*.nuspec'
versioningScheme: 'byEnvVar'
versionEnvVar: releaseVersion
verbosityPack: 'detailed'
- task: NuGetCommand#2
displayName: 'Push Release Nuget Packages'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/release'))
continueOnError: true
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'FEED'
verbosityPush: 'detailed'
- task: PublishSymbols#2
displayName: 'Publish Symbols to Symbol Server'
inputs:
SearchPattern: '**/bin/**/*.pdb'
SymbolServerType: 'TeamServices'
- ${{ if eq(parameters.ArtifactPublish, true) }}:
- ${{ each artifact in parameters.Artifacts }}:
- task: CopyFiles#2
displayName: 'Copy .artifactignore: ${{ artifact.ArtifactPath }}'
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: '.artifactignore'
TargetFolder: '$(Build.SourcesDirectory)/${{ artifact.ArtifactPath }}'
- ${{ each artifact in parameters.Artifacts }}:
- task: PublishPipelineArtifact#1
displayName: 'Publish Artifact: ${{ artifact.ArtifactName }}'
inputs:
targetPath: '$(Build.SourcesDirectory)/${{ artifact.ArtifactPath }}'
artifactName: '${{ artifact.ArtifactName }}'
Yaml file that consumes it:
trigger:
- release
- development
- master
- feature/*
- task/*
resources:
repositories:
- repository: templates
name: Project/Repo-Name
type: git
ref: refs/heads/release
variables:
# This is the version displayed in package manager (Major.Minor.BuildNumber)
majorVersion: 1
minorVersion: 1
jobs:
- template: Templates/build.yml#templates
parameters:
Solution: 'SolutionName'
ArtifactPublish: true
Artifacts:
- ArtifactPath: 'bin/directory/$(buildConfiguration)'
ArtifactName: 'ArtifactName'
You have one Publish Symbols task in your template, this task will publish symbols to the symbol server in Azure Artifacts with a random name. That's why we can see the extra artifact in Published tab, it's expected behavior when using PublishSymbols#2 task.
I'm just curious about why the extra file is being published as well
as preventing it.
It's not recommended to disable or remove the Publish Symbols step though it helps to remove the artifact. This task is quite important for some scenarios where you want to have the ability to debug the published nuget packages, check my another similar issue. So my suggestion is just ignoring it~

How can I set the EnvironmentName for XML transformation during a deployment job?

Alright folks, giving Azure multi-stage-pipelines feature a go and not having much luck getting xml transformations using a deployment job to work.
Update: This is not using the Classic Deploy/Release UI in Azure DevOps
What I've done so far:
remove transformations from the build process. Attempting to build once and deploy everywhere
verified that the web.{stage}.config files are included in the webdeploy package by removing node in csproj
Set up stage with name of 'Development'
pipeline yaml
trigger:
batch: false # If batch set to true, when a pipeline is running, the system waits until the run is completed,
branches:
include:
- staging-devops
paths:
include:
- myProject/*
- API/*
variables:
BuildConfiguration: 'Release'
BuildPlatform: 'Any CPU'
System.Debug: true
stages:
- stage: Build
displayName: 'Build project'
jobs:
- job:
displayName: 'Build and package client'
pool:
vmImage: 'vs2017-win2016'
demands:
- msbuild
- visualstudio
steps:
- task: VSBuild#1
displayName: 'Visual Studio build'
inputs:
solution: 'myProject/myProject.csproj'
vsVersion: '15.0'
msbuildArgs: '/p:DeployOnBuild=true /p:AutoParameterizationWebConfigConnectionStrings=False /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: 'AnyCPU'
configuration: 'Release'
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(build.artifactstagingdirectory)'
artifactName: 'myProject-web-client'
- job:
displayName: 'Build and package API'
pool:
vmImage: 'vs2017-win2016'
demands:
- msbuild
- visualstudio
steps:
# add caching of nuget packages
- task: NuGetToolInstaller#0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: 'API/myAPI.sln'
- task: VSBuild#1
displayName: 'Visual Studio build'
inputs:
solution: 'API/myAPI.sln'
vsVersion: '15.0'
msbuildArgs: '/p:DeployOnBuild=true /p:AutoParameterizationWebConfigConnectionStrings=False /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: '$(BuildPlatform)'
# configuration: '$(BuildConfiguration)'
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(build.artifactstagingdirectory)'
artifactName: 'myProject-api'
- stage: Development
displayName: 'Development'
dependsOn: Build
condition: succeeded('Build') #add check if artifact is available
jobs:
- deployment: DeploymyProjectClient
displayName: 'Deploy web client'
timeoutInMinutes: 30
pool:
vmImage: "windows-latest"
environment:
name: Staging
resourceType: VirtualMachine
tags: web
strategy:
runOnce:
deploy:
steps:
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'Deploy web application (myProject)'
inputs:
webSiteName: myProjectDev
package: '$(Pipeline.Workspace)/myProject-web-client/**/*.zip'
removeAdditionalFilesFlag: true
- deployment: Development
displayName: 'Development'
timeoutInMinutes: 30
pool:
vmImage: "windows-latest"
environment:
name: Staging
resourceType: VirtualMachine
tags: web
strategy:
runOnce:
deploy:
steps:
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: Development
inputs:
webSiteName: 'WebAPI-Test'
package: '$(Pipeline.Workspace)/myProject-api/**/*.zip'
xmlTransformation: true
I've tried variations of the stage name, displayname, deployment name, etc still can't get the transformation for the Development stage to fire.
I do get the web.config and web.release.config to work but that is it.
2020-05-02T05:26:04.9272125Z ##[debug]adjustedPattern: 'C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\**/*.config'
2020-05-02T05:26:04.9343033Z ##[debug]9 matches
2020-05-02T05:26:04.9345300Z ##[debug]9 final results
2020-05-02T05:26:04.9351908Z ##[debug]Applying XDT Transformation : C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\Content\D_C\a\1\s\API\obj\Debug\Package\PackageTmp\Web.Release.config -> C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\Content\D_C\a\1\s\API\obj\Debug\Package\PackageTmp\Web.config
When reviewing the log file for deployment I do see the following
##[debug]Release.EnvironmentName=undefined
How can I set the stage name properly in order for the transformations to be applied during deployment??
How can I set the EnvironmentName for XML transformation during a deployment job?
This is known issue that has already been reported to product team.
As workaround, you could try to set the variable Release.EnvironmentName on the stage-level and on the job-level:
- stage: Development
displayName: 'Development'
dependsOn: Build
condition: succeeded('Build') #add check if artifact is available
variables:
Release.EnvironmentName: Development
jobs:
Then, the environment-specific config transformation was triggered.
Hope this helps.
Please try $(System.StageName).

Multistage pipeline not working as expected

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'
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.

Resources