3
votes

I am setting up a new Azure DevOps pipeline for my webapp. I can see that the build artifacts are saved in a path called $Build.ArtifactStagingDirectory. Where this path variable is pointing to and how long I can access my artifact?

Also, Does Azure DevOps versions(keep track of all the artifacts built over a time) the artifacts built? If no, how to version my build artifacts?

3

3 Answers

9
votes

In the agent there are 3 folders: a, b and s. The variable $(Build.ArtifactStagingDirectory) point to folder a (artifacts), so the path is c:\agent\_work\1\a (if the agent location is c:\agent, the 1 can be another number also, according to how many builds there are, this number is incremental).

The artifacts not saved there! when you build the code all the code and the artifacts exist on folder s (sources), the best practice is to copy only the artifacts to folder a and then use the task "Publish build artifacts", in this task you take the artifacts from folder a and put them on Azure DevOps storage or in your file share (if you use self-hosted agent).

From the Azure DevOps storage / file share the artifacts exist according to your retention policy.

If you save the artifacts in Azure DevOps you can access your artifacts from the build summary page or create a release pipeline. if you save them in a file share you can just access them there or in the release pipeline.

1
votes

You need to publish artifacts using task as by default they are not published. If you are using yaml just add

# Publish Build Artifacts
# Publish build artifacts to Azure Pipelines/TFS or a file share
- task: PublishBuildArtifacts@1
  inputs:
    #pathtoPublish: '$(Build.ArtifactStagingDirectory)' 
    #artifactName: 'drop' 
    #publishLocation: 'Container' # Options: container, filePath
    #targetPath: # Required when publishLocation == FilePath
    #parallel: false # Optional
    #parallelCount: # Optional

There is configuration how long to keep those artifacts as i remember by default is 30 days and 3 or 5 last builds

-1
votes

You can control how many days you want to keep each build (default 30 days) before deleting it (See Build and release retention policies). When a build is deleted, the published artifacts also gets deleted.

To version your build artifacts you can use the build number which will keep track.

Where the $Build.ArtifactStagingDirectory is pointing to depends on which publish location you are choosing. See Artifacts in Azure Pipelines