# How to check if an artifact exists before downloading?

**URL:** <https://forum.buildkite.community/t/how-to-check-if-an-artifact-exists-before-downloading/2002>\
**Category:** Pipelines\
**Created:** [April 26, 2022, 3:49am UTC](https://forum.buildkite.community/t/how-to-check-if-an-artifact-exists-before-downloading/2002 "2022-04-26T03:49:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TJACOB](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@TJACOB](https://forum.buildkite.community/u/TJACOB)\
**Post date:** [April 26, 2022, 3:49am UTC](https://forum.buildkite.community/t/how-to-check-if-an-artifact-exists-before-downloading/2002/1 "2022-04-26T03:49:52Z")

</div>

Step 1 of my build will produce an artifact if the step fails.  
And I am uploading this artifact to be used subsequet steps.

Step 2 will download the uploaded aritifacts to do some further processing.

The issue I am facing is that that the artifact is only generated if Step 1 fails. If it passes, then Step 2 will fail since artifact doesn’t exist.

Is there a way to check if an artifact exist before it can be downloaded ?

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [April 26, 2022, 4:22am UTC](https://forum.buildkite.community/t/how-to-check-if-an-artifact-exists-before-downloading/2002/2 "2022-04-26T04:22:17Z")

</div>

Hey @TJACOB 👋

There sure is! You can use `buildkite-agent meta-data exists`. The docs on this command can be found at [buildkite-agent meta-data v3 | Buildkite Documentation](https://buildkite.com/docs/agent/v3/cli-meta-data#checking-if-data-exists).

- Jarryd

---

<div class="post-metadata">

**Author:** ![TJACOB](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@TJACOB](https://forum.buildkite.community/u/TJACOB)\
**Post date:** [April 26, 2022, 6:05am UTC](https://forum.buildkite.community/t/how-to-check-if-an-artifact-exists-before-downloading/2002/3 "2022-04-26T06:05:14Z")

</div>

Thanks @paula for the reply.

I have tried the below

```auto
$ buildkite-agent meta-data exists "<artifact name>"

```

and it hasn’t worked for me. Am I missing something ?

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [April 26, 2022, 6:12am UTC](https://forum.buildkite.community/t/how-to-check-if-an-artifact-exists-before-downloading/2002/4 "2022-04-26T06:12:33Z")

</div>

That could mean that it doesn’t exist. The command will exit success if it exists and will exit with return code 100 if it doesn’t. If it returns 100, it will cause your second step to be marked as failed.

You might need to wrap the command in an if/test to capture the failing case but still exit your second step with success.

---

<div class="post-metadata">

**Author:** ![adamsnimbus](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@adamsnimbus](https://forum.buildkite.community/u/adamsnimbus)\
**Post date:** [July 7, 2023, 5:03am UTC](https://forum.buildkite.community/t/how-to-check-if-an-artifact-exists-before-downloading/2002/5 "2023-07-07T05:03:01Z")

</div>

The correct command for this is `buildkite-agent artifact search "<artifact_name>"`

> By default, searches exit 1 if there are no results.

[https://buildkite.com/docs/agent/v3/cli-artifact](https://buildkite.com/docs/agent/v3/cli-artifact)
