How to check if an artifact exists before downloading?

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 ?

Hey @TJACOB :wave:

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.

- Jarryd

Thanks @jarryd for the reply.

I have tried the below

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

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

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.