我已经在 ubuntu 15.10 上安装了 Jenkins。在 shell 构建步骤中,我尝试创建一个 Python 虚拟环境并激活它:
但是当我运行该作业时出现以下错误:
/tmp/hudson4515625893361069094.sh: 9: /tmp/hudson4515625893361069094.sh: source: not found
日志中还有更多内容:
[django-demo] $ /bin/sh -xe /tmp/hudson4515625893361069094.sh
+ virtualenv --no-site-packages virtual_django
New python executable in virtual_django/bin/python2
Also creating executable in virtual_django/bin/python
Installing setuptools, pip...done.
Running virtualenv with interpreter /usr/bin/python2
+ cd virtual_django/bin
+ pwd
/var/lib/jenkins/workspace/django-demo/virtual_django/bin
+ dir
activate activate.fish easy_install pip pip2.7 python2
activate.csh activate_this.py easy_install-2.7 pip2 python python2.7
+ source activate
/tmp/hudson4515625893361069094.sh: 9: /tmp/hudson4515625893361069094.sh: source: not found
Build step 'Execute shell' marked build as failure
因此虚拟环境已成功创建,但无法激活,因为来源找不到命令。
我确实验证了我确实可以运行源激活 以 jenkins 用户身份在相应工作区中从机器上的终端运行命令:
jenkins@vmi63860 ~/workspace/django-demo/virtual_django/bin ((HEAD detached at 290c6a4)) $ source activate
(virtual_django)jenkins@vmi63860 ~/workspace/django-demo/virtual_django/bin ((HEAD detached at 290c6a4)) $ exit
那么为什么当我在 Jenkins 作业下运行它时它会失败?
答案1
在这里找到了类似的帖子:
解决办法是添加:
#!/bin/bash
在脚本步骤的第一行:
答案2
source 是 bash/ksh/etc 的扩展,作为 的更“实质”的同义词提供。
尝试使用下面
. activate