Options for running the "store_artifacts" step conditionally

Hi, I have a question as to what options there are for setting up a configuration file to run a store_artifacts job step conditionally, but on a condition that depends on a value known only at runtime and not at compile-time.

If I wanted to do this based on a value that’s known at compile-time, I know I can use when with condition. However, for values known only at runtime, my understanding is this approach can’t be used. Thus, my question is — what alternatives are there?

The only approach I’ve thought of so far is to make store_artifacts the last step in the job, and then to insert a step before this that runs circleci-agent step halt conditionally on an environment variable whose value is computed at runtime. (I haven’t actually tried this yet, but I’m assuming it will work.)

Are there any other approaches? The above approach doesn’t seem ideal because it requires store_artifacts to be the last step (since circleci-agent step halt stops the job). Thanks in advance.