Reputation: 279
I need to run jenkins build using a specific conda environment on our jenkins server (running on Windows). I thought it would be as easy as running:
activate myenv
python test_env.py
but this seems to cause the build to exit instead, before the script even starts. Here is the jenkins console log:
activate myenv
Activating environment "myenv"...
Finished: SUCCESS
If I remove the activate line, the python script executes fine.
FYI, the script I am running:
import os
f = open('env.txt','w')
for k, v in os.environ.iteritems():
print k, v
f.write('%s\t%s\n' % (k,v))
f.close()
Does anybody know what is going on? Should I directly call the relevant python executable instead?
Upvotes: 10
Views: 7036
Reputation: 91610
Use call activate myenv
to prevent activate from ending the current shell when it is finished. See https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/call.mspx?mfr=true.
Upvotes: 11
Reputation: 279
Bradley led me in the right direction and I found the solution...
I needed a windows equivalent for the Unix "source", and "call" does the job, as detailed in this other answer.
batch equivalent of "source" on windows: how to run a python script from a virtualenv
I hope someone will find this helpful in the future!
Upvotes: 4
Reputation: 1155
I think the activate script on Windows starts a new subshell which means the current shell exists immediately. Can you try manually setting the ENV variables like PATH and such instead of using activate?
Upvotes: 2