Publish and download pipeline Artifacts

Azure DevOps Services

Using Azure Pipelines, yous tin download artifacts from earlier stages in your pipeline or from another pipeline. You can also publish your antiquity to a file share or make it bachelor as a pipeline artifact.

Publish artifacts

You lot tin can publish your artifacts using YAML, the classic editor, or Azure CLI:

Note

Publishing pipeline artifacts is not supported in release pipelines.

  • YAML
  • YAML (task)
  • Classic
  • Azure CLI
                  steps: - publish: $(System.DefaultWorkingDirectory)/bin/WebApp   artifact: WebApp                                  

Although the artifact'due south name is optional, it is a good practice to specify a proper name that accurately reflects the contents of your artifact. If you lot plan to consume the artifact from a job running on a different OS, y'all must ensure all the file paths are valid for the target environs. For example, a file name containing the character \ or * will fail to download on Windows.

The path of the file/folder that you desire to publish is required. This can exist an absolute or a relative path to $(System.DefaultWorkingDirectory).

Packages in Azure Artifacts are immutable. Once you publish a package, its version volition be permanently reserved. rerunning failed jobs volition fail if the package has been published. A adept mode to arroyo this if you want to be able to rerun failed jobs without facing an error package already exists, is to utilise Conditions to only run if the previous job succeeded.

                              jobs:   - job: Job1     steps:       - script: echo Hello Job1!    - job: Job2     steps:       - script: echo Hello Job2!     dependsOn: Job1                          

Caution

Deleting a pipeline run will result in the deletion of all Artifacts associated with that run.

Use .artifactignore

.artifactignore uses a like syntax to .gitignore (with few limitations) to specify which files should exist ignored when publishing artifacts. Come across Utilise the .artifactignore file for more details.

Note

The plus sign character + is not supported in URL paths and some builds metadata for package types such as Maven.

Example: ignore all files except .exe files:

              **/* !*.exe                          

Important

Azure Artifacts automatically ignore the .git binder path when you don't accept a .artifactignore file. You can bypass this past creating an empty .artifactignore file.

Download artifacts

You tin download artifacts using YAML, the classic editor, or Azure CLI.

  • YAML
  • YAML (task)
  • Classic
  • Azure CLI
                  steps: - download: current   antiquity: WebApp                                  
  • current: download artifacts produced by the current pipeline run. Options: current, specific.

Note

List of published artifacts will be available simply in following dependant jobs. Therefore, utilise current option only in split jobs, that has dependency on jobs with publish artifacts tasks.

Tip

You can use Pipeline resource to define your source in one place and use it anywhere in your pipeline.

By default, files are downloaded to $(Pipeline.Workspace). If an artifact name was non specified, a subdirectory will be created for each downloaded artifact. You tin employ matching patterns to limit which files become downloaded. See File matching patterns for more details.

              steps: - download: current   artifact: WebApp   patterns: |     **/*.js     **/*.zip                          

Artifacts selection

A single download step can download 1 or more artifacts. To download multiple artifacts, leave the artifact proper noun field empty and use file matching patterns to limit which files will be downloaded. ** is the default file matching pattern (all files in all artifacts).

Unmarried artifact

When an artifact proper noun is specified:

  1. Simply files for that specific artifact are downloaded. If the artifact does not exist, the chore will fail.

  2. File matching patterns are evaluated relative to the root of the artifact. For example, the pattern *.jar matches all files with a .jar extension at the root of the antiquity.

The following case illustrates how to download all *.js from an artifact WebApp:

  • YAML
  • YAML (chore)
  • Classic
  • Azure CLI
                  steps: - download: current   artifact: WebApp   patterns: '**/*.js'                                  

Multiple artifacts

When no artifact name is specified:

  1. Multiple artifacts can exist downloaded and the task does non fail if no files are found.

  2. A subdirectory is created for each antiquity.

  3. File matching patterns should assume the first segment of the pattern is (or matches) an artifact name. For case, WebApp/** matches all files from the WebApp artifact. The pattern */*.dll matches all files with a .dll extension at the root of each artifact.

The following example illustrates how to download all .zip files from all artifacts:

  • YAML
  • YAML (task)
  • Archetype
  • Azure CLI
                  steps: - download: current   patterns: '**/*.zip'                                  

Artifacts in release and deployment jobs

Artifacts are simply downloaded automatically in deployment jobs. The download artifact task will be machine injected only when using the deploy lifecycle hook in your deployment. To terminate artifacts from beingness downloaded automatically, add a download pace and set its value to none. In a regular build job, you need to explicitly use the download step keyword or the Download Pipeline Artifact chore. Encounter lifecycle hooks to larn more about the other types of hooks.

              steps: - download: none                          

Note

Deleting or overwriting Pipeline Artifacts is not currently supported. The recommended workflow if you want to re-run a failed pipeline job is to include the job ID in the artifact name. $(system.JobId) is the appropriate variable for this purpose. See System variables to larn more about predefined variables.

Use Artifacts across stages

If you lot want to be able to access your artifact across different stages in your pipeline, y'all tin employ output variables to pass it to the next stage in your YAML. See Dependency expressions for more details.

              trigger: none pool:   vmImage: 'ubuntu-latest' stages: - stage: A   jobs:   - job: A1     steps:      - script: echo ##vso[task.setvariable variable=shouldrun;isOutput=true]true        proper noun: printvar - phase: B   dependsOn: A   jobs:   - job: B1     condition: in(stageDependencies.A.A1.result, 'Succeeded', 'SucceededWithIssues', 'Skipped')     steps:     - script: echo hi from Job B1   - job: B2     condition: eq(stageDependencies.A.A1.outputs['printvar.shouldrun'], 'truthful')     steps:      - script: echo howdy from Job B2                          

Case

In the following example, nosotros will copy and publish a script binder from our repo to the $(Build.ArtifactStagingDirectory). In the 2nd phase, we will download and run our script.

Screenshot showing the PowerShell task output

              trigger: - main stages: - phase: build   jobs:   - task: run_build     pool:       vmImage: 'windows-latest'     steps:     - task: VSBuild@1       inputs:         solution: '**/*.sln'         msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'         platform: 'Any CPU'         configuration: 'Release'      - task: CopyFiles@ii       displayName: 'Re-create scripts'       inputs:         contents: 'scripts/**'         targetFolder: '$(Build.ArtifactStagingDirectory)'      - publish: '$(Build.ArtifactStagingDirectory)/scripts'       displayName: 'Publish script'       artifact: drib  - phase: examination   dependsOn: build   jobs:   - chore: run_test     pool:       vmImage: 'windows-latest'     steps:     - download: current       artifact: drop     - job: PowerShell@2       inputs:         filePath: '$(Pipeline.Workspace)\drop\exam.ps1'                          

Drift from build artifacts

Pipeline artifacts are the next generation of build artifacts and are the recommended mode to work with artifacts. Artifacts published using the Publish Build Artifacts task tin can withal be downloaded using Download Build Artifacts, but we recommend using the latest Download Pipeline Artifact chore instead.

When migrating from build artifacts to pipeline artifacts:

  1. For build artifacts, it'due south mutual to copy files to $(Build.ArtifactStagingDirectory) and then use the Publish Build Artifacts task to publish this folder. With the Publish Pipeline Artifact job, you can but publish directly from the path containing the files.

  2. By default, the Download Pipeline Artifact task downloads files to $(Pipeline.Workspace). This is the default and recommended path for all types of artifacts.

  3. File matching patterns for the Download Build Artifacts task are expected to first with (or match) the artifact proper noun, regardless if a specific antiquity was specified or non. In the Download Pipeline Artifact task, patterns should non include the artifact name when an artifact name has already been specified. For more information, encounter single artifact selection.

FAQ

Q: What are build artifacts?

A: Build artifacts are the files generated by your build. Run into Build Artifacts to learn more near how to publish and consume your build artifacts.

Q: Tin this task publish artifacts to a shared folder?

A: Not currently, but this characteristic is planned.

  • Build artifacts
  • Releases in Azure Pipelines
  • Release artifacts and artifact sources
  • How to mitigate chance when using private package feeds