Skip to content
Latchkey

How to Publish and Download Pipeline Artifacts in Azure Pipelines

Jobs run on separate agents, so a producer publishes a named pipeline artifact and a consumer downloads it by the same name.

Publish a directory with PublishPipelineArtifact@1, then in a later job that dependsOn it, restore the same artifact name with DownloadPipelineArtifact@2.

Steps

  • Publish the output folder under a fixed artifactName.
  • Add dependsOn on the consuming job so it runs after the producer.
  • Download the same artifact name into a known path.

Pipeline

azure-pipelines.yml
jobs:
  - job: build
    steps:
      - script: npm run build
      - task: PublishPipelineArtifact@1
        inputs:
          targetPath: dist
          artifactName: web
  - job: ship
    dependsOn: build
    steps:
      - task: DownloadPipelineArtifact@2
        inputs:
          artifact: web
          path: $(Pipeline.Workspace)/web
      - script: ./publish.sh $(Pipeline.Workspace)/web

Gotchas

  • Artifact names must be unique within a run; suffix with a matrix value when fanning out.
  • Pipeline artifacts are faster than the older build artifacts for most workflows.
  • For dependency trees prefer the Cache@2 task over publishing an artifact.

Related guides

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