简体   繁体   English

使用Jenkins运行Python脚本

[英]Running Python Scripts with Jenkins

I am looking to schedule my python script runs with jenkins. 我正在计划使用jenkins运行我的python脚本。 The issue is, my scripts use a lot of libs like pandas etc that are installed on my mac terminal. 问题是,我的脚本使用了很多Mac终端上安装的库,例如pandas等。

Is there a way to allow Jenkins to pick up these modules (or run the scripts as if it was terminal)? 有没有办法让詹金斯(Jenkins)选择这些模块(或像运行终端程序一样运行脚本)? Also is there a way to run Python3 in jenkins? 还可以在jenkins中运行Python3吗?

I have already configured Jenkins to execute from custom workspace and have tried both shell and plugin executions. 我已经将Jenkins配置为从自定义工作区执行,并尝试了Shell和插件执行。

The answer is yes, but it is detailed so I can only give you high level steps here. 答案是肯定的,但是它很详细,所以我在这里只给您高层的步骤。 Jenkins can execute command line statements, and python modules can be run from the command line. Jenkins可以执行命令行语句,而python模块可以从命令行运行。

I would start by using the begins library to create a python file to run from the command line with arguments. 我将从使用Begins开始创建一个python文件,该文件从带有参数的命令行运行。 Get it working on your local machine that way. 以这种方式在本地计算机上运行它。

You will want to use either virtualenv or venv, and do all your pip installs using that virtual environment. 您将要使用virtualenv或venv,并使用该虚拟环境进行所有pip安装。 Then you can copy the virtual environment to your Jenkins machine, or create a new one. 然后,您可以将虚拟环境复制到您的Jenkins机器上,或创建一个新环境。 Look into the freeze tool. 查看冻结工具。

When calling your python from jenkins, you must first activate your virtual environment just as if you were working on it yourself. 从jenkins调用python时,必须首先激活虚拟环境,就像您自己在使用它一样。

You have a lot of research to do, but is very doable. 您有很多研究要做,但是非常可行。 I can help with follow up questions if needed. 如有需要,我可以协助您解决后续问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM