Skip to content

Instantly share code, notes, and snippets.

@wehappyfew
Last active September 8, 2015 12:07
Show Gist options
  • Select an option

  • Save wehappyfew/306911b309a0816c7c83 to your computer and use it in GitHub Desktop.

Select an option

Save wehappyfew/306911b309a0816c7c83 to your computer and use it in GitHub Desktop.
The python project is in Jenkin's workspace folder. I want to run a python script on the QA server (Linux).The workspace folder's path must be added (on runtime for now) in the sys.path .That way I can make imports into the script from any module of the project. TODO->For a more permanent solution the path must be hardcoded in a var in the machine.
__author__ = 'wehappyfew'
import sys,os,pprint
# check the sys.path before I add my directory
print("1: -- ",sys.path)
if os.name == "posix": # check if the script runs on Linux
# If I comment it out, it will throw ImportError
# This path should always be appended on runtime,
# otherwise should be added on the server as ENVIRONMENTAL VARIABLE
sys.path.append("/var/lib/jenkins/jobs/QA_Project/workspace/")
# check the sys.path after I add my directory
print pprint.pprint("2: -- ",sys.path)
from TheProject import helpers #imports a simple var located to another file/module that prints "Hello world"
print helpers.hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment