Artifacts in Azure Pipelines

Azure DevOps Services | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018

Note

We recommend using Download Pipeline Artifacts and Publish Pipeline Artifacts for faster performance.

Azure Artifacts enables teams to use feeds and upstream sources to manage their dependencies. You can use Azure Pipelines to publish and download different types of artifacts as part of your CI/CD workflow.

Publish artifacts

Artifacts can be published at any stage of your pipeline. You can use YAML or the classic Azure DevOps editor to publish your packages.

- powershell: gci env:* | sort-object name | Format-Table -AutoSize | Out-File $env:BUILD_ARTIFACTSTAGINGDIRECTORY/environment-variables.txt

- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop
  • pathToPublish: the path of your artifact. This can be an absolute or a relative path. Wildcards are not supported.
  • artifactName: the name of your artifact.

Note

Make sure you are not using one of the reserved folder names when publishing your artifact. See Application Folders for more details.

YAML is not supported in TFS.

Example: Use multiple tasks

- powershell: gci env:* | sort-object name | Format-Table -AutoSize | Out-File $env:BUILD_ARTIFACTSTAGINGDIRECTORY/environment-variables.txt

- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop1
- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop2
  • pathToPublish: the path of your artifact. This can be an absolute or a relative path. Wildcards are not supported.
  • artifactName: the name of your artifact.

YAML is not supported in TFS.

Example: Copy and publish binaries

- powershell: gci env:* | sort-object name | Format-Table -AutoSize | Out-File $env:BUILD_ARTIFACTSTAGINGDIRECTORY/environment-variables.txt

- task: CopyFiles@2
  inputs:
    sourceFolder: '$(Build.SourcesDirectory)'
    contents: '**/$(BuildConfiguration)/**/?(*.exe|*.dll|*.pdb)'
    targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop
  • sourceFolder: the folder that contains the files you want to copy. If you leave this empty, copying will be done from $(Build.SourcesDirectory).
  • contents: File paths to include as part of the copy.
  • targetFolder: destination folder.
  • pathToPublish: the folder or file path to publish. It can be an absolute or a relative path. Wildcards are not supported.
  • artifactName: the name of the artifact that you want to create.

Note

Make sure not to use reserved name for artifactName such as Bin or App_Data. See ASP.NET Web Project Folder Structure for more details.

YAML is not supported in TFS.

Download artifacts

- powershell: gci env:* | sort-object name | Format-Table -AutoSize | Out-File $env:BUILD_ARTIFACTSTAGINGDIRECTORY/environment-variables.txt

- task: DownloadBuildArtifacts@0
  inputs:
    buildType: 'current'
    downloadType: 'single'
    artifactName: 'drop'
    downloadPath: '$(System.ArtifactsDirectory)'
  • buildType: specify which build artifacts will be downloaded: current (the default value) or from a specific build.
  • downloadType: choose whether to download a single artifact or all artifacts of a specific build.
  • artifactName: the name of the artifact that will be downloaded.
  • downloadPath: path on the agent machine where the artifacts will be downloaded.

YAML is not supported in TFS.

Note

If you are using a deployment task, you can reference your build artifacts using $(Agent.BuildDirectory). See Agent variables for more details.

When your pipeline run is completed, navigate to Summary to explore or download your artifact.

Published build artifact

When your pipeline run is completed, select Artifacts to download your artifact.

Published build artifact TFS

Publish from TFS to a UNC file share

If you're using a private Windows agent, you can set the artifact publish location option (TFS 2018 RTM and older: artifact type) to publish your files to a UNC file share.

Note

Use a Windows build agent. This option doesn't work for macOS and Linux agents.

Choose file share to copy the artifact to a file share. Common reasons to do this:

  • The size of your drop is large and consumes too much time and bandwidth to copy.

  • You need to run some custom scripts or other tools against the artifact.

If you use a file share, specify the UNC file path to the folder. You can control how the folder is created for each build by using variables. For example: \\my\share\$(Build.DefinitionName)\$(Build.BuildNumber).

Tips

  • Use forward slashes in file path arguments. Backslashes don't work in macOS/Linux agents.

  • Build artifacts are stored on a Windows filesystem, which causes all UNIX permissions to be lost, including the execution bit. You might need to restore the correct UNIX permissions after downloading your artifacts from Azure Pipelines or TFS.

  • Build.ArtifactStagingDirectory and Build.StagingDirectory are interchangeable.

  • Build.ArtifactStagingDirectory path is cleaned up after each build.

  • Deleting a build associated with packages published to a file share will result in the deletion of all Artifacts in that UNC path.

  • If you are publishing your packages to a file share, make sure you provide access to the build agent.