无法使用 jenkins 运行 python 脚本

2024-06-23

我正在尝试运行 Python 作业。我创建了以下文件夹:

C:\Users\herod\jenkins_ws\workspace\window_testing

并向其中添加脚本“testing.py”。

该脚本非常简单:

if __name__ == "__main__":
    print "hellow world !"
    f = open('test_log.txt','w')
    f.write("hello\n")
    f.close

但是从 Jenkins 运行它时出现以下错误(如果我从命令行运行它它可以工作):

>Building remotely on windows1 (widndows_genereal) in workspace C:\Users\herod\jenkins_ws\workspace\window_testing
[window_testing] $ python C:\windows\TEMP\hudson5234791200924972506.py
    The system cannot find the file specified
    FATAL: command execution failed
    java.io.IOException: Cannot run program "python" (in directory "C:\Users\herod\jenkins_ws\workspace\window_testing"): CreateProcess error=2, The system cannot find the file specified
        at java.lang.ProcessBuilder.start(Unknown Source)
        at hudson.Proc$LocalProc.<init>(Proc.java:244)
        at hudson.Proc$LocalProc.<init>(Proc.java:216)
        at hudson.Launcher$LocalLauncher.launch(Launcher.java:775)
        at hudson.Launcher$ProcStarter.start(Launcher.java:355)
        at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1024)
        at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:991)

我究竟做错了什么 ?

这是我尝试过的:

  • 在构建部分的作业配置中,我选择“执行Python脚本”,然后输入testing.py文件 - 不起作用。

  • 我还尝试输入 python test.py 和 python.exe testing.py - 不起作用。

  • 尝试在“脚本”编辑文本中编写 python 脚本 - 不起作用。

  • 如果我将执行类型从 python 更改为批处理文件,那么它显示它通过了,但实际上它没有运行 python 脚本。

update2:(尝试 Technext 解决方案后)我收到下一个错误:

Building remotely on windows1 (widndows_genereal) in workspace C:\Users\herod\jenkins_ws\workspace\window_testing
[window_testing] $ python C:\Users\herod\AppData\Local\Temp\hudson4767788636447260218.py
Traceback (most recent call last):
  File "C:\Users\herod\AppData\Local\Temp\hudson4767788636447260218.py", line 1, in <module>
    testing.py
NameError: name 'testing' is not defined
Build step 'Execute Python script' marked build as failure
Finished: FAILURE

每当在批处理文件中将 python 作为命令运行时,请提供 Python 可执行文件的完整路径,否则您必须在 Jenkins 环境中配置该路径。假设你的 python 可执行文件保存在C:\Python27文件夹,然后执行以下命令:

C:\Python27\python.exe <full path of python file to execute>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 jenkins 运行 python 脚本 的相关文章

  • 什么时候在Python中使用弱引用?

    谁能解释一下弱引用的用法吗 The 文档 http docs python org library weakref html没有具体解释 只是说GC可以随时销毁通过弱引用链接到的对象 那么拥有一个随时可能消失的物体还有什么意义呢 如果我需要
  • 使用不带引号的块样式的 Python YAML 转储

    如何使用 PyYAML 加载和转储 YAML 以便它尽可能地使用原始样式 我有 Python 来加载和转储 YAML 数据 例如 import sys import yaml def represent dictorder self dat
  • 如何将 typeshed 与 mypy 一起使用?

    我克隆了typeshed https github com python typeshed但我不知道如何告诉 mypy 使用它包含的类型提示 我在 mypy help 中没有看到任何选项 mypy 存储库确实包含对 typeshed 存储库
  • Python:访问另一个类中一个类的属性和方法

    假设我有两个 A 类和 B 类 Class A A s attributes and methods here Class B B s attributes and methods here 现在我可以评估 B 类对象中 A 的属性 如下所
  • 使用 setuptools (pip) 时如何打印警告和错误

    我正在使用 setuptools 来打包代码 以便可以使用以下命令轻松安装它 cd project name pip install 在设置过程中 我想警告用户有关预先存在的配置文件的信息 并在系统上打印一些安装后说明 例如 etc pro
  • Django CollectStatic 启动大文件上传时管道损坏

    我正在尝试使用collectstatic将静态文件上传到我的S3存储桶 但我收到一个700k javascript文件的管道损坏错误 这就是错误 Copying Users wedonia work asociados server aso
  • 使用 Python 访问内存映射文件

    我希望利用激战 2 中的内存映射文件 该文件旨在链接到 Mumble 以获得位置音频 该文件包含有关字符坐标的信息和其他有用的信息 我已经能够使用此脚本访问坐标信息 import mmap import struct last while
  • os.walk 无需深入研究下面的目录

    我该如何限制os walk只返回我提供的目录中的文件 def dir list self dir name whitelist outputList for root dirs files in os walk dir name for f
  • Python Jinja2 调用宏会导致(不需要的)换行符

    我的 JINJA2 模板如下所示 macro print if john name if name John Hi John endif endmacro Hello World print if john Foo print if joh
  • Python 中没有名称属性的表单提交

    背景 在Python中使用urllib和urllib2 您可以进行表单提交 您首先创建一个字典 formdictionary search stackoverflow 然后使用 urllib 的 urlencode 方法来转换这个字典 pa
  • [Python]比较两个 zip 文件的函数,一个位于 FTP 目录中,另一个位于我的本地计算机上

    我在创建比较两个 zip 文件的函数时遇到问题 如果它们相同 而不仅仅是名称相同 这是我的代码示例 def validate zip files self host 192 168 0 1 port 2323 username 123 pa
  • 如何在 Google App Engine (Python) 中定义配置变量/常量?

    我是 python GAE 的新手 想知道如何快速定义和使用全局设置变量 所以说你 git 克隆我的 GAE 应用程序 然后打开config yaml 添加更改设置 应用程序就全部连接起来 如下所示 config yaml or whate
  • 如何循环遍历列表中除最后一项之外的所有项? [复制]

    这个问题在这里已经有答案了 Using a for循环 如何循环遍历列表中除最后一项之外的所有项 我想遍历一个列表 检查每个项目与后面的项目 我可以在不使用索引的情况下做到这一点吗 for x in y 1 If y是一个生成器 那么上面的
  • matplotlib 后端 - 我关心吗?

    gt gt gt import matplotlib gt gt gt print matplotlib rcsetup all backends u GTK u GTKAgg u GTKCairo u MacOSX u Qt4Agg u
  • 用于监视文件夹和更新数据库的 Python 守护进程

    这专门用于管理 MP3 文件 但它应该可以轻松地适用于任何包含大量文件的目录结构 我想找到或编写一个守护程序 最好用Python 来监视一个包含许多子文件夹的文件夹 这些子文件夹都应该包含X个MP3文件 每当添加 更新或删除文件时 它都应该
  • ValueError:序列太大;不能大于 32

    我写了这段代码 from Crypto Cipher import AES import numpy as np import cv2 base64 BLOCK SIZE 16 PADDING pad lambda s s BLOCK SI
  • Maya python 连接选择的属性

    我一直在尝试制作一个简单的脚本 它将采用两个视口选择 然后基本上将第二个视口的旋转连接到第一个 我不确定如何正确地从视口选择中为对象创建变量 这是我的尝试 但不起作用 import maya cmds as cmds sel cmds ls
  • print() 函数的有趣/奇怪的机制

    我正在学习Python 我目前正在学习如何定义自己的函数 并且在尝试理解返回值和打印它之间的区别时遇到了一些困难 我读到的关于这个主题的描述对我来说不太清楚 所以我开始自己尝试 我想我现在已经明白了 如果我没记错的话 区别在于你可以传递 a
  • 如何限制单元测试的最大运行时间?

    我目前正在运行一些单元测试 这些测试可能需要很长时间才能失败或无限期地运行 在成功的测试运行中 它们总是会在一定的时间内完成 是否可以创建一个 pytest 单元测试 如果在一定时间内未完成 该测试就会失败 您可以安装 pytest tim
  • Mac 无法安装 Tensorflow

    我检查了我的 pip3 和 python3 版本 tensorflow MacBook Pro de Hector 2 tensorflow hectoresteban pip3 V pip 10 0 1 from Users hector

随机推荐