# Run a pipeline with an artifact version

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

Start a pipeline with a chosen artifact version from the Run window, CLI, artifact triggers or the Trigger pipeline action, and read the BUDDY_RUN_ARTIFACT_* variables.

You can run a pipeline with a selected artifact version, the same way you run it with a selected commit. The files of that version go to the working directory of the run, and the actions have `BUDDY_RUN_ARTIFACT_*` variables, with no separate Download Artifact Version action.

The artifact version can be selected in the **Run** window, using the Buddy CLI, through the **Trigger pipeline** action, or through an artifact trigger. All methods require the pipeline to have at least the **Read-only** permission level for the artifact.

## Artifact context configuration

The **Artifact version** field in the Run window appears in a pipeline with an artifact context or an artifact trigger. You add the context in the pipeline's **Workflow** tab, in the **Contexts** section, with the **+** button.

![Artifact context in the Workflow tab of a pipeline](https://buddy.works/docs/artifacts/artifacts-pipeline-artifact-context.png)

In pipeline YAML, the context is the `artifacts` list:

```yaml
- pipeline: deploy-release
  name: Deploy release
  refs:
  - refs/heads/main
  artifacts:
  - my-app-build:3.*
  actions:
  - action: Show release
    type: BUILD
    docker_image_name: library/ubuntu
    docker_image_tag: "24.04"
    commands: |-
      echo "Release $BUDDY_RUN_ARTIFACT_VERSION"
      ls -la
```

An entry has the form `name:version` and can contain a wildcard. [Scopes](https://buddy.works/docs/artifacts/scopes.md#scope-in-pipeline-context-and-triggers) describes the `scope` field and the full object notation.

Runs started through the API and MCP need the context too, because the run gets the files of the selected version and the `BUDDY_RUN_ARTIFACT_*` variables from it.

The pattern defined in the artifact context does not restrict version selection. In the **Run** window, matching versions are highlighted at the top of the list, followed by versions of other artifacts in the workspace. Versions that do not match the pattern can also be selected for execution.

## Artifact version selection in the UI

In the pipeline's **Run** window, open the **Artifact version** field, select one or more versions, click **Apply** and then **Run now**. Each selected version starts a separate run.

![Artifact version picker in the Run window](https://buddy.works/docs/artifacts/artifacts-run-version-picker.png)

After the run starts, the label of the selected version is shown next to the run in the **Runs** list.

![Pipeline runs with artifact version labels](https://buddy.works/docs/artifacts/artifacts-run-header-version.png)

If the selected commit and artifact version are the same as in the last run of the pipeline, the warning **RUN: CONTEXT ALREADY EXECUTED** appears above the form. The warning does not block the run.

## Running pipelines using the CLI

`bdy pipeline run start` takes the artifact version in the `-a` option, in the `name:version` format:

```bash
bdy pipeline run start deploy-release -a my-app-build:3.2.0 -p my-project
```

You can combine `-a` with `-e` and an environment name. The [CLI reference](https://buddy.works/docs/cli/pipeline/run/start.md) describes all options.

## Artifact version files and run variables

A run with an artifact version has its files in the working directory, next to the repository files, and `BUDDY_RUN_ARTIFACT_*` variables:

```
BUDDY_RUN_ARTIFACT=my-app-build
BUDDY_RUN_ARTIFACT_ID=<artifactId>
BUDDY_RUN_ARTIFACT_NAME=my-app-build
BUDDY_RUN_ARTIFACT_URL=https://app.buddy.works/my-workspace/my-project/artifacts/<artifactId>/versions
BUDDY_RUN_ARTIFACT_VERSION=3.2.0
BUDDY_RUN_ARTIFACT_VERSION_RAW_URL=https://3-2-0-my-app-build-my-workspace.bucket-2.registry.sh
BUDDY_RUN_ARTIFACT_VERSION_URL=https://app.buddy.works/my-workspace/my-project/artifacts/<artifactId>/versions/<versionId>
```

The `BUDDY_RUN_` prefix distinguishes these variables from `BUDDY_ARTIFACT_*`, which the Publish Artifact Version action sets during the run ([Artifacts in pipelines](https://buddy.works/docs/artifacts/pipelines.md)).

> **Warning**
>
> Version files overwrite files with the same names, but do not remove the others. If version `1.0.0` had an `assets/` directory and `3.1.0` does not, the `assets/` directory is still in the pipeline filesystem after a run with `3.1.0`. For versions with a different structure, turn on **Erase filesystem & cache**.

## Start a pipeline on an artifact event

An artifact trigger starts a pipeline after a version is created or published and passes that version to the run. The run has the same `BUDDY_RUN_ARTIFACT_*` variables and `BUDDY_RUN_EVENT_TYPE`, e.g. `PUBLISH_ARTIFACT_VERSION`. [On artifact event](https://buddy.works/docs/pipelines/introduction/triggering-pipelines/on-artifact-event.md) describes the trigger configuration.

- `bdy artifact publish my-app-build:3.1.0 ./dist` fires the Created trigger first and Published a few seconds later,
- an empty version created through the API fires only Created; Published appears only after files are uploaded to it,
- a pipeline with a Published trigger starts separately for each version published by one Publish Artifact Version action, e.g. `build-$BUDDY_RUN_ID` and `latest`; the `my-app-build:build-*` pattern in the trigger skips `latest`,
- a version copy (`bdy artifact version create ... --from`) fires Created.

The **Read-only** level is enough for a run started by a trigger.

## Pass a version to the next pipeline

The Trigger pipeline action passes an artifact version to the pipeline it starts in the `artifact` field. The target run has the files and `BUDDY_RUN_ARTIFACT_*` variables, the same as after selecting a version in the Run window.

```yaml
- action: Promote to production
  type: RUN_NEXT_PIPELINE
  pipeline: deploy-release
  artifact: my-app-build:$BUDDY_RUN_ARTIFACT_VERSION
  wait: true
```

With a variable in the `artifact` field, the pipeline passes on the same version it was started with, e.g. from a test pipeline to a deployment pipeline. Prepare the target pipeline the same way as for a run from the Run window: with an `artifacts` context and access to the artifact. [Trigger pipeline action](https://buddy.works/docs/pipelines/introduction/triggering-pipelines/trigger-pipeline-action.md) describes the `wait` field and other action options.

## Cancel older runs of the same version

`cancel_inprogress_runs: SAME_ARTIFACT` stops a run in progress when a new run with the same artifact version starts. A run with a different version of the same artifact keeps running in parallel.

```yaml
- pipeline: deploy-release
  name: Deploy release
  refs:
  - refs/heads/main
  artifacts:
  - my-app-build:3.*
  concurrent_pipeline_runs: true
  cancel_inprogress_runs: SAME_ARTIFACT
```

The stopped run has the **Terminated** status, with no information about which run replaced it.

`skip_queued_runs: SAME_ARTIFACT` applies to queued runs. When two runs with the same artifact version are waiting to start, the older one ends with the **Skipped** status and the newer one executes. A queued run with a different version executes normally. [Concurrency & parallelism](https://buddy.works/docs/pipelines/concurrency-and-parallelism.md) describes the other values of both fields.

See also:

- [Artifacts in pipelines](https://buddy.works/docs/artifacts/pipelines.md) - the Publish and Download actions and `BUDDY_ARTIFACT_*` variables
- [On artifact event](https://buddy.works/docs/pipelines/introduction/triggering-pipelines/on-artifact-event.md) - Created, Published and Deleted triggers
- [Permissions and access](https://buddy.works/docs/artifacts/permissions-and-access.md) - pipeline access levels for an artifact
- [Versions](https://buddy.works/docs/artifacts/versions.md) - version names, copying and the run history of a version


---
Original source: https://buddy.works/docs/artifacts/run-with-version