Publish Build Artifacts task

Azure Pipelines | TFS 2018 | TFS 2017 | TFS 2015.3

Use this task in a build pipeline to publish build artifacts to Azure Pipelines, TFS, or a file share.


Looking to get started working with build artifacts? See Artifacts in Azure Pipelines.



YAML snippet

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


Argument Description
Path to publish Path to the folder or file you want to publish. The path must be a fully-qualified path or a valid path relative to the root directory of your repository. ($(Build.ArtifactStagingDirectory)) is the most common value and is what should be used in most cases. Subdirectories of the specified path will not be published. Wildcards in the path are not supported. See Artifacts in Azure Pipelines.
Artifact name Specify the name of the artifact that you want to create. It can be whatever you want. For example: drop
Artifact publish location In most cases, Azure Pipelines/TFS (Server on TFS 2018 RTM and older) is the best and simplest option. Otherwise, choose a file share and then specify a few more arguments (see below). If left empty or container is specified, it will have the same effect as specifying Azure Pipelines/TFS. To learn more, see Artifacts in Azure Pipelines.
File share path Specify the path to the file share where you want to copy the files. The path must be a fully-qualified path or a valid path relative to the root directory of your repository. Publishing artifacts from a Linux or macOS agent to a file share is not supported.
Parallel copy (Azure Pipelines, TFS 2018, or newer) Select whether to copy files in parallel using multiple threads for greater potential throughput. If this setting is not enabled, a single thread will be used.
Parallel count (Azure Pipelines, TFS 2018, or newer) Enter the degree of parallelism (the number of threads) used to perform the copy. The value must be at least 1 and not greater than 128. Choose a value based on CPU capabilities of the build agent. Typically, 8 is a good starting value.
Control options


A typical pattern for using this task is:

  • Build something
  • Copy build outputs to a staging directory
  • Publish staged artifacts

For example:

- script: ./
- task: CopyFiles@2
    contents: '_buildOutput/**'
    targetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
    pathToPublish: $(Build.ArtifactStagingDirectory)
    artifactName: MyBuildOutputs

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

Q: I'm having problems. How can I troubleshoot them?

A: Try this:

  1. On the variables tab, add system.debug and set it to true. Select to allow at queue time.

  2. In the explorer tab, view your completed build and click the build step to view its output.

The control options arguments described above can also be useful when you're trying to isolate a problem.

Q: How do variables work? What variables are available for me to use in the arguments?

A: $(Build.SourcesDirectory) and $(Agent.BuildDirectory) are just a few of the variables you can use. Variables are available in expressions as well as scripts; see variables to learn more about how to use them. There are some predefined build and release variables you can also rely on.