Can I access the value in an env file from a python script using os.getenv?

Hi,

I have a question about the new environment files we should use instead of the set env. I am using an env variable to store the current tag number to pass it to a python script.

      - name: Setup Env Variable only on tag
        run: echo ::set-env name=GH_BUILD_NR::${GITHUB_REF/refs\/tags\//}
        if: startsWith(github.ref, 'refs/tags/')

And in my python script I used:

build_number = os.getenv('GH_BUILD_NR')

Does this still work with the new files?

Yes, under the same conditions as before: The Python script must be called in a later step that’s part of the same job.

@siedlerchr,

Sure, using “os.getenv(‘ENV_NAME’)” or “os.environ[‘ENV_NAME’]” in Python scripts to access environment variables still can work.

In addition, the old workflow command (echo “::set-env name={name}::{value}”) to set an environment variable has been deprecated.
Currently, the old command still can work in the workflows, however we recommend that you use the new command (echo “{name}={value}” >> $GITHUB_ENV).
More details, see “Setting an environment variable”.