I would like to programmatically determine if a particular Python script is run a testing environment such as
etc. I realize that this will require some heuristics, but that's good enough for me. Are certain environment variables always set? Is the user name always the same? Etc.
An environment variable is generally set for each CI/CD pipeline tool.
The ones I know about:
os.getenv("GITHUB_ACTIONS")
os.getenv("TRAVIS")
os.getenv("CIRCLECI")
os.getenv("GITLAB_CI")
Will return true
in a python script when executed in the respective tool environment.
e.g:
os.getenv("GITHUB_ACTIONS") == "true"
in a Github Action workflow.os.getenv("CIRCLECI") == "true"
in a CircleCI pipeline.PS: If I'm not mistaken, to identify the python script is being executed in Jenkins
or Kubernetes Service host
, the behavior isn't the same.