Custom target: how to generate an unique id shared by all envs in the same run

Hello,
I need to generate a unique build id that is different every time i execute my custom target. (this id is the timestamp of the ota package I’m building)

I have 2 envs, and each time I execute pio run -t ota, my script is executed for each env and generate the package. However, since I’m using a timestamp, the two packages will end up with different name.

I tried to save in a file the result, but then I do not know if the file is from a previous run or not.

It would be nice if platformio can provide an common env that persist across envs from the same run (and can be modified by the script) or something in the env that tells if this is the first env and the last env (or maybe total number of envs and the current env index)

Thanks!