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

PIZ*_*ZZA 8 python jenkins jenkins-plugins

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

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

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

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

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
Run Code Online (Sandbox Code Playgroud)

Avi*_*ash 12

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

#!/bin/sh
python <absolute_path_of_python_script>.py
Run Code Online (Sandbox Code Playgroud)


dsa*_*don 9

您可以将所有python脚本实际复制到Build部分下的"execute shell"中,而不是在每个服务器上处理本地脚本文件.它必须从相关的python shebang开始.例如:

#!/usr/bin/env python
your script...
Run Code Online (Sandbox Code Playgroud)

您还可以在作业中添加参数并在python脚本中使用环境变量.例如

parameter1 = os.environ['parameter1']
Run Code Online (Sandbox Code Playgroud)