# Artifacts in pipelines

> For AI agents: the complete documentation index is at https://buddy.works/llms.txt

Use the Publish Artifact Version and Download Artifact Version actions to pass build files between pipelines and read the BUDDY_ARTIFACT_* variables.

The **Publish Artifact Version** action publishes files from the pipeline filesystem or repository as artifact versions. The **Download Artifact Version** action downloads artifact version files to the pipeline filesystem. The Publish Artifact Version action also exports `BUDDY_ARTIFACT_*` variables containing information about the published version for use in subsequent actions.

A basic example with one pipeline that publishes and another that downloads is in the [Quickstart](https://buddy.works/docs/artifacts/quickstart.md).

## Required permissions

In the artifact's **Permissions** tab, the pipeline needs **Read-only** to download, **Read-write** to publish and **Manage** for the Artifact Cleanup action. [Permissions and access](https://buddy.works/docs/artifacts/permissions-and-access.md) describes how to set access, and [Troubleshooting](https://buddy.works/docs/artifacts/troubleshooting.md) lists the error messages.

## Publish Artifact Version action

The **Publish Artifact Version** action copies files from the pipeline filesystem or from the repository to one or more artifact versions.

![Publish Artifact Version action form](https://buddy.works/docs/artifacts/artifacts-publish-action-form.png)

In the action form, set:

- **Target artifact** - the artifact name; if the artifact does not exist, the action creates it,
- **Versions separated by comma** - version names, e.g. `build-$BUDDY_RUN_ID, latest`; variables work in names,
- **Source** - **Pipeline Filesystem** for files from earlier actions or **Buddy Repository** for files from the repository,
- **Pipeline filesystem path** - the directory to publish, e.g. `/dist`.

The same action in YAML:

```yaml
- action: Publish build
  type: PUBLISH_ARTIFACT_VERSION
  artifact: my-app-build
  versions:
  - build-$BUDDY_RUN_ID
  - latest
  input_type: BUILD_ARTIFACTS
  local_path: /dist
```

The `artifact`, `versions` and `local_path` fields match the form fields. `input_type: BUILD_ARTIFACTS` is the **Pipeline Filesystem** source, not Buddy artifacts.

The **Delete files removed in changeset** option (on by default) removes files that are not in the source directory from the version. When you turn it off (`deletion_disabled: true`), those files stay in the version, unless you turn on **Always deploy from scratch** (`always_from_scratch: true`), which clears the version before uploading files. The [action YAML reference](https://buddy.works/docs/yaml/yaml-actions/publish-artifact-version.md) describes the other fields.

### Publishing multiple versions

Each item in the `versions` list is a separate version with the same files. In the run log, the action has a setup entry with a separate step for each version below it, so you can see which publish failed.

![Publish artifact version action log with output variables](https://buddy.works/docs/artifacts/artifacts-publish-run-log.png)

For example, the `versions` list can contain `build-$BUDDY_RUN_ID` and `latest`. The first entry creates a version named after the run ID. The `latest` version is updated on each run because it is explicitly included in the list. It does not automatically reference the most recently published version.

### Output variables

After publishing, the following pipeline actions have `BUDDY_ARTIFACT_*` variables with the details of the published version. An example from run #3 of a pipeline that publishes to `my-app-build`:

```
BUDDY_ARTIFACT=my-app-build
BUDDY_ARTIFACT_ID=<artifactId>
BUDDY_ARTIFACT_NAME=my-app-build
BUDDY_ARTIFACT_URL=https://app.buddy.works/my-workspace/my-project/artifacts/<artifactId>/versions
BUDDY_ARTIFACT_VERSION=build-3
BUDDY_ARTIFACT_VERSION_RAW_URL=https://build-3-my-app-build-my-workspace.bucket-2.registry.sh
BUDDY_ARTIFACT_VERSION_URL=https://app.buddy.works/my-workspace/my-project/artifacts/<artifactId>/versions/<versionId>
```

- `BUDDY_ARTIFACT_VERSION_RAW_URL` is the address of the version files, e.g. to send in a notification or to test with `curl`.
- `BUDDY_ARTIFACT_VERSION_URL` and `BUDDY_ARTIFACT_URL` point to the version view and the version list in Buddy.

> **Info**
>
> When the `versions` list has several items, the variables point to the first one. For the list `build-$BUDDY_RUN_ID`, `latest`, the `BUDDY_ARTIFACT_VERSION` variable has the value `build-3`, not `latest`. Put the version you want to pass on first in the list.

A run started with an artifact version or by an artifact trigger has a different set of variables, with the `BUDDY_RUN_ARTIFACT_*` prefix. [Run a pipeline with an artifact version](https://buddy.works/docs/artifacts/run-with-version.md) describes it.

## Download Artifact Version action

The **Download Artifact Version** action saves the files of the selected version in the pipeline filesystem.

![Download Artifact Version action form](https://buddy.works/docs/artifacts/artifacts-download-action-form.png)

In the action form, set:

- **Artifact** and **Version** - the artifact and the exact version name, e.g. `1.1.0` or `build-42`,
- **Version path** - a file or directory in the version; `/` downloads the whole version,
- **Filesystem target path** - a directory in the pipeline filesystem,
- **Overwrite** - overwrites files that are already in the target directory.

The pipeline filesystem persists between runs. Enable **Overwrite** to replace existing files in the destination directory. To prevent files from previous versions from remaining in the filesystem, clear the destination directory before downloading.

Example YAML configuration:

```yaml
- action: Download release
  type: DOWNLOAD_ARTIFACT_VERSION
  artifact: my-app-build
  version: 1.1.0
  destination_path: /downloaded
  overwrite: true
```

In YAML, **Version path** is `source_path`, **Filesystem target path** is `destination_path`, and **Overwrite** is `overwrite`. The [action YAML reference](https://buddy.works/docs/yaml/yaml-actions/download-artifact-version.md) describes file filters and the other fields.

Version files also reach the filesystem without a separate action when you run the pipeline with a selected artifact version ([Run a pipeline with an artifact version](https://buddy.works/docs/artifacts/run-with-version.md)).

## Publishing to Environment-scoped artifacts

A pipeline publishes to an artifact with Environment scope only when the environment is assigned to the pipeline and the run executes in that environment. A run in the environment is not enough if the pipeline does not have the environment assigned.

```yaml
- pipeline: publish-to-staging
  name: Publish to staging
  refs:
  - refs/heads/main
  environments:
  - staging
  actions:
  - action: Publish
    type: PUBLISH_ARTIFACT_VERSION
    artifact: my-app-config
    versions:
    - run-$BUDDY_RUN_ID
    input_type: BUILD_ARTIFACTS
    local_path: /dist
```

The action has no environment field, so the environment comes from the pipeline and run settings. [Scopes](https://buddy.works/docs/artifacts/scopes.md) describes scopes.

## Artifact Cleanup action

A third action, **Artifact Cleanup**, removes versions that match a pattern, e.g. all `build-*`. It requires the Manage level. [Cleanup and retention](https://buddy.works/docs/artifacts/cleanup-and-retention.md) describes its configuration and examples.

See also:

- [Quickstart](https://buddy.works/docs/artifacts/quickstart.md) - the first pipeline that publishes and downloads a version
- [Run a pipeline with an artifact version](https://buddy.works/docs/artifacts/run-with-version.md) - the Run window, triggers and `BUDDY_RUN_ARTIFACT_*` variables
- [Container images in actions](https://buddy.works/docs/artifacts/using-artifact-images.md) - an image from the artifact registry as the action environment
- [Pipeline filesystem](https://buddy.works/docs/pipelines/introduction/pipeline-filesystem.md) - the directory actions publish from and download files to
- [Troubleshooting](https://buddy.works/docs/artifacts/troubleshooting.md) - action error messages and their causes


---
Original source: https://buddy.works/docs/artifacts/pipelines