TJACOB
April 26, 2022, 3:49am
1
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 ?
paula
April 26, 2022, 4:22am
2
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 .
- Jarryd
TJACOB
April 26, 2022, 6:05am
3
Thanks @paula 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 ?
paula
April 26, 2022, 6:12am
4
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.
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