How to activate conda environment in jenkins build

I need to run jenkins build using a specific conda environment on our jenkins server (works on Windows). I thought it would be as easy as working:

activate myenv python test_env.py 

but it looks like this will cause the build to complete before the script starts. Here is the jenkins console log:

 activate myenv Activating environment "myenv"... Finished: SUCCESS 

If I delete the activation string, the python script runs fine.

FYI, script I run:

 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 anyone know what is going on? Should I directly call the appropriate python executable?

+7
python windows environment jenkins conda
source share
3 answers

Use call activate myenv to prevent activation after the end of the current shell. See https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/call.mspx?mfr=true .

+9
source share

Bradley led me in the right direction and I found a solution ...

I needed the Windows equivalent for the Unix β€œsource”, and β€œcall” does the job, as described in this other answer.

windows source equivalent package: how to run python script from virtualenv

I hope someone finds this useful in the future!

+3
source share

I think that activating the script on Windows launches a new subshell, which means that the current shell exists immediately. Can you try manually setting ENV variables like PATH and activating instead?

+2
source share

All Articles