gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:36:28 28 4
gpt4 key购买 nike

我是 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com