How to get the Git-Revision on a pio remote machine?

Hi guys,

I am trying to include version information in my firmware using a python script assembling version information from Gitlab-CI variables or - if build locally - a Git SHA. Basically, I am following this howto (Redirecting...) with a few tweaks. The build works locally, but if I try to upload the firmware to the system via my remote agent it fails complaining that it cannot find the python script.
In my platformio.ini file:

build_flags =
    !python .ci/build_rev.py

Running “platformio remote run --target upload” yields:

python: can't open file '.ci/build_rev.py': [Errno 2] No such file or directory

Has anyone experienced something similar and possibly a solution?

Edit:
Ok, I previously missed that files that should be shared with remote machines have to reside in the “shared” folder. See here: Redirecting...

Putting my script in there works… almost, because on the remote machine the script is not executed inside a Git-repository and thus cannot find the revision information.

So the question now is, how can I pass the revision from the build machine to the remote?

It would sure be nice if it was possible to pass environment variables along with “pio remote run”, but that seems not to be the case, so I now started creating additional files in the “shared” folder containing the information I need on the remote machine. I suspect this to work at some point, but it is way too complicated for what should be a very simple task.

So, I am still looking for better solutions… any suggestions?