如何配置Jenkins来运行Python脚本



我通过anaconda在EC2 Ubuntu实例上安装了python。

python返回的命令*/home/ubuntu/anaconda3/bin/python*Jenkins安装在*/var/lib/jenkins*

我正在尝试运行一个简单的";Hello World"保存在名为*test.py*的文件中并位于*/home/ubuntu/scripts/*文件夹中的脚本。

*python /home/ubuntu/scripts/test.py*在终端上运行时;执行shell";詹金斯。

为什么以及如何配置Jenkins来逐步运行python脚本?

问题是anaconda-python安装仅对用户可用"ubuntu";。为了让Jenkins能够运行python脚本;詹金斯;用户需要使用该安装。

为了解决这个问题,我就是这么做的:

  1. 以jenkins身份使用命令sudo su -s /bin/bash jenkins登录
  2. 将python安装位置编辑为export PATH=/home/ubuntu/anaconda3/bin:$PATH
  3. 通过which python检查路径是否正确
  4. 以ubuntu用户身份重新登录
  5. 通过sudo service jenkins restart重新启动Jenkins(不确定是否需要(

现在我可以通过Jenkins运行python脚本了。

最新更新