Skip to content
Latchkey

How to Publish Build Artifacts in Azure Pipelines

Azure Pipelines stores output with the PublishPipelineArtifact task and retrieves it downstream with DownloadPipelineArtifact.

Publish a folder as a named pipeline artifact; a later job that dependsOn the producer downloads it by name. Pipeline artifacts are faster than legacy build artifacts.

Publish then download

The build job publishes dist; the deploy job downloads it before deploying.

azure-pipelines.yml
jobs:
  - job: build
    steps:
      - script: npm ci && npm run build
      - task: PublishPipelineArtifact@1
        inputs:
          targetPath: '$(System.DefaultWorkingDirectory)/dist'
          artifact: dist
  - job: deploy
    dependsOn: build
    steps:
      - task: DownloadPipelineArtifact@2
        inputs:
          artifact: dist
          path: '$(Pipeline.Workspace)/dist'
      - script: ./deploy.sh $(Pipeline.Workspace)/dist

Gotchas

  • Prefer PipelineArtifact tasks over the older PublishBuildArtifacts@1 - they are faster and dedup content.
  • Artifact names must be unique within a run; in a matrix, suffix the name with the leg.
  • A downstream job must declare dependsOn the producer or the artifact will not be available.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →