MSDN Tutorials

Explore the power of Azure DevOps Pipelines

📦 Pipeline Artifacts

Learn how to publish and consume build outputs with pipeline artifacts.

Introduction to Artifacts

In Azure Pipelines, artifacts are files that are produced as a result of a build or release. These can include compiled code, executables, libraries, configuration files, or any other output generated during your pipeline's execution. Artifacts are crucial for passing outputs from one stage of a pipeline to another, or for making them available for download and use outside the pipeline.

Artifacts ensure that the outputs of your build are versioned, traceable, and easily accessible, promoting a reproducible build and deployment process.

Publishing Artifacts

You can publish artifacts using the PublishBuildArtifacts task in classic pipelines or the PublishBuildArtifacts@1 task in YAML pipelines.

YAML Example

azure-pipelines.yml


pipeline:
  jobs:
  - job: Build
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - script: echo "Hello, Artifacts!" > my_output.txt
      displayName: 'Create a sample file'

    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(System.DefaultWorkingDirectory)/my_output.txt'
        ArtifactName: 'my_sample_artifact'
        publishLocation: 'Container'
      displayName: 'Publish Sample Artifact'
                

In this example:

Consuming Artifacts

Artifacts published in one job can be automatically downloaded to subsequent jobs in the same pipeline. If you need to explicitly download them or download artifacts from a different pipeline, you can use the DownloadBuildArtifacts task (classic) or DownloadBuildArtifacts@0 task (YAML).

YAML Example (Consuming in a subsequent job)

azure-pipelines.yml


pipeline:
  jobs:
  - job: Build
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - script: echo "Hello, Artifacts!" > my_output.txt
      displayName: 'Create a sample file'
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(System.DefaultWorkingDirectory)/my_output.txt'
        ArtifactName: 'my_sample_artifact'
      displayName: 'Publish Sample Artifact'

  - job: Consume
    pool:
      vmImage: 'ubuntu-latest'
    dependsOn: Build
    steps:
    - task: DownloadBuildArtifacts@0
      inputs:
        buildType: 'current'
        downloadType: 'single'
        artifactName: 'my_sample_artifact'
        downloadPath: '$(System.ArtifactsDirectory)'
      displayName: 'Download my_sample_artifact'

    - script: cat $(System.ArtifactsDirectory)/my_sample_artifact/my_output.txt
      displayName: 'Verify artifact content'
                

In the Consume job:

Types of Artifacts

Azure Pipelines supports various artifact types:

Best Practices