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
dependsOnon the consuming job so it runs after the producer. - Download the same
artifactname 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)/webGotchas
- 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
How to Cache Dependencies in Azure PipelinesSpeed up Azure Pipelines by caching a package store with the Cache@2 task, keyed on a lockfile hash so unchan…
How to Order Stages With dependsOn in Azure PipelinesControl stage execution order in Azure Pipelines with dependsOn, chaining build, test, and deploy stages so e…