As a beginner in all things Azure DevOps, understanding when folders are created and populated by the pipeline tasks is the first step to learning how to manipulate it to suit your needs.
Using Visual Studio I created an ASP.NET based project (named TestApplication). The YAML file shown below was the template created by Azure DevOps, following this tutorial. However, the VSBuild@1 task was modified using this, as it resulted in a more suitable folder structure. I also added a PublishBuildArtifacts@1.
trigger: - master pool: vmImage: 'windows-latest' variables: solution: '**/TestApplication.sln' buildPlatform: 'ANY CPU' # x86 buildConfiguration: 'Release' buildversion: 1.0.0 steps: - task: NuGetToolInstaller@1 - task: NuGetCommand@2 inputs: restoreSolution: '$(solution)' - task: VSBuild@1 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 inputs: platform: '$(buildPlatform)' configuration: '$(buildConfiguration)' - task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(build.artifactStagingDirectory)' ArtifactName: '$(buildversion)' publishLocation: 'Container'
I ran this YAML file multiple times using PowerShell tasks to display the environment variables at different stages of the pipeline.
Most of this information, though publicly available on the Microsoft docs, is not very intuitive to a beginner. I hope that this table summarizes the usage of the most relevant directories.
|/a||This is the working director for agent a.||Agent.WorkFolder|
|/a/1/a||Artifact staging directory. This is where the VS Build task results are stored in. The publish build artifacts task creates an artifact of whatever is in this folder. Note - it gets purged before each new build.||Build.StagingDirectory, System.ArtifactsDirectory, Build.ArtifactStagingDirectory|
|/a/1/b||The output folder for compiled binaries.||Build.BinariesDirectory|
|/a/1/s||Source directory. This is the working directory and where your source code is stored.||Build.SourcesDirectory, System.DefaultWorkingDirectory|
This information was very helpful to me when it came down to customizing a YAML for my project. I wasn't able to find any existing documentation or articles like this, so please feel free to add links in the comments to similar articles if they exist.