python - 如何在 Jenkins UI 中执行本地 python 脚本

标签 python jenkins jenkins-plugins

我是 Jenkins 的新手,最近想安排一个作业来执行本地 python 脚本。我还没有源代码控制,所以在 Jenkins UI 中创建作业时,我在源代码管理中选择了“无”。

我做了一些关于如何在 Jenkins UI 中执行 python 脚本的研究,我尝试使用 Python 插件来执行 python 脚本作为构建步骤。但它失败了。 (但实际上我不想使用这个插件,因为我的脚本接受输入参数,所以我想我需要在 BUILD 字段中选择类似“execute shell”的东西——我试过了但也失败了)谁能帮我找出方法正确运行/调用本地 python 脚本?

PS:我也不清楚Jenkins Workspace 及其工作原理?如果有人可以为我澄清,将是适当的。

这是我在构建失败后得到的控制台输出:

Started by user Yiming Chen
[EnvInject] - Loading node environment variables.
Building in workspace D:\Application\Jenkins\workspace\downloader
[downloader] $ sh -xe C:\windows\TEMP\hudson3430410121213277597.sh
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "sh" (in directory     "D:\Application\Jenkins\workspace\downloader"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.<init>(Proc.java:245)
at hudson.Proc$LocalProc.<init>(Proc.java:214)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:846)
at hudson.Launcher$ProcStarter.start(Launcher.java:384)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:108)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:65)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1728)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:404)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 16 more
Build step 'Execute shell' marked build as failure
Finished: FAILURE

最佳答案

创建一个 Jenkins 作业并从 jenkins 作业中将您的脚本作为 shell 脚本运行。 像这样

#!/bin/sh
python <absolute_path_of_python_script>.py

关于python - 如何在 Jenkins UI 中执行本地 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41931790/

相关文章:

python - 没有括号打印不起作用(Python 2.7)

azure - Jenkins - 无法创建用户数据目录 :/var/lib/jenkins/snap/docker/: Read-only file system

jenkins 不断抛出错误消息 431 原因 : Request Header Fields Too Large

Jenkins 和 Copy Artifact 插件 : Overwrite existing file in target project?

python - BeautifulSoup 从 find_all 获取文本

python - 为什么没有作为输出?

maven - 如何使用 Maven 获取 Jenkins 内部版本号

Jenkins 在 Mac M1 代理上无法正常工作

jenkins - 使用Jenkins Groovy管道脚本中的ci-game

python - 如何将 json 对象列表转换为单个 pyspark 数据帧?