如何通过Jenkinsfile激活conda环境?

时间:2016-08-21 12:04:53

标签: jenkins conda

通过终端,它就像source activate MyCondaEnv一样简单,但如果我尝试使用Jenkins文件:

sh '. /home/rwardrup/anaconda3/bin/activate MyCondaEnv',

Jenkins控制台返回:

Running shell script
+ . /home/rwardrup/anaconda3/bin/activate MyCondaEnv
+ [[ -n ]]
/var/lib/jenkins/workspace/testing/features@tmp/durable-bb4a4c30/script.sh: 4: /home/rwardrup/anaconda3/bin/activate: [[: not found
+ [[ -n ]]
/var/lib/jenkins/workspace/testing/features@tmp/durable-bb4a4c30/script.sh: 7: /home/rwardrup/anaconda3/bin/activate: [[: not found
+ echo Only bash and zsh are supported
Only bash and zsh are supported
+ return 1

我试过在那里投掷一个小朋友:sh '$!/bin/bash. /home/rwardrup/anaconda3/bin/activate MyCondaEnv',认为这可能与此有关,我得到:

Running shell script
+ /bin/bash. /home/rwardrup/anaconda3/bin/activate MyCondaEnv
/var/lib/jenkins/workspace/testing/features@tmp/durable-2a550d19/script.sh: 2: /var/lib/jenkins/workspace/testing/features@tmp/durable-2a550d19/script.sh: /bin/bash.: not found

有没有办法通过Jenkinsfile激活和使用Conda环境?我发现了一些关于使用Django venv in a Jenkinsfile的信息,但这在我的情况下并不起作用。

1 个答案:

答案 0 :(得分:4)

看起来像shebang的错误语法和后面的missng换行符。

试试这个:

sh '''#!/bin/bash
     . /home/rwardrup/anaconda3/bin/activate MyCondaEnv
'''