0

I am trying to automate build, test, and deployment via CI/CD. I have a python script designed to query my git remote repository, select the most recent tag in semantic versioning format (x.x.x) and increment it depending on the type of change.

I would like to set my environment variable (GIT_NEW_VERSION) so that this can be used within my Makefile and the generated binary will have the version available. The problem with this is that the python script is run in a sub-process that doesn't have access to the parent process variables. So I can modify the variable only for the current process and any processes created after but not the process that called the python script.

I could call make from the python script but that is not ideal for error management and logging with my CI tool.

jb1681
  • 51
  • 1
  • 8
  • `os.putenv(varname, value)` – kaza Sep 29 '17 at 19:05
  • @bulbus Thanks for the suggestion but that only modifies the current process variable. Not the parent process variable. Once I exit the python environment the variable is no longer set as I want it to be. – jb1681 Sep 29 '17 at 19:25
  • see [this](https://stackoverflow.com/questions/488366/how-do-i-make-environment-variable-changes-stick-in-python) – kaza Sep 29 '17 at 19:32

1 Answers1

0

bash:

LD_LIBRARY_PATH=my_path
sqsub -np $1 /path/to/executable

Similar, in Python:

import os
import subprocess
import sys

os.environ['LD_LIBRARY_PATH'] = "my_path" # visible in this process + all children
subprocess.check_call(['sqsub', '-np', sys.argv[1], '/path/to/executable'],
                      env=dict(os.environ, SQSUB_VAR="visible in this subprocess"))
Gowtham Balusamy
  • 728
  • 10
  • 22
  • 1
    As I stated above, I want to modify the parent rather than the current process and children. I've also seen this answer elsewhere before posting. – jb1681 Sep 29 '17 at 19:13