user2402428
user2402428

Reputation:

Setting up a specific Python in Jenkins

I am quite new with configuring Jenkins or Python but I have to set up a unitary test in Jenkins. My program is in Python, but only works on Python 2.6 whereas the Jenkins version I should be using is 2.7, so I'm trying to set up Jenkins to set some environment variables so that it prepares launching the accurate Python for that specific test (it is part of a greater project that will successfully run several other tests that work well).

The idea I had was to set in the command to execute several environment variables like PATH, LD_LIBRARY_PATH and PYTHONPATH such as following in the "Execute shell" command line interpreter:

PYTHONPATH=/path/to/python2.6/lib:$PYTHONPATH
PATH=/path/to/python2.6/bin:$PATH
LD_LIBRARY_PATH=/path/to/python2.6/lib:$LD_LIBRARY_PATH

... however, it was still calling the wrong version of Python. Therefore, I forced these variables to:

PYTHONPATH=/path/to/python2.6/lib
PATH=/path/to/python2.6/bin
LD_LIBRARY_PATH=/path/to/python2.6/lib

... and I still get errors because the old version of Python is called instead, even if it should not appear in the PATH ... It appears Jenkins will remember the location of the old libraries however and will try loading them first.

How would I correctly set the environment in a "subproject" in Jenkins so that I can call a different version of Python?

Thank you and best regards,

~Stéphane

Upvotes: 2

Views: 22360

Answers (3)

user2402428
user2402428

Reputation:

Stupid me... I was indeed doing things correctly, I just had a part of my code that was overriding the PYTHONPATH value, so the solution I had found previously was good. FYI, I modified my shebang, if it's of any help to anyone ;)

Upvotes: 0

BjornArnelid
BjornArnelid

Reputation: 151

What i did in my Jenkins shell script using a specific python version was something like this when calling my unit test:

python3 src/test/unit_test.py

I was using it to use Python 3.X but it should work with 2.6 as well using:

python2.6 src/test/unit_test.py

Upvotes: 1

loopbackbee
loopbackbee

Reputation: 23322

If you want your program to run with a specific version of the python interpreter, you indicate it in the shebang

#!/usr/bin/python2.6
#your code here

Upvotes: 4

Related Questions