Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to activate conda environment in jenkins build

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?

like image 539
Jahfet Avatar asked Aug 28 '14 10:08

Jahfet


2 Answers

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.

like image 161
asmeurer Avatar answered Oct 21 '22 13:10

asmeurer


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!

like image 22
Jahfet Avatar answered Oct 21 '22 13:10

Jahfet