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?
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With