【问题标题】:How to schedule/run python script remotely using jenkins如何使用詹金斯远程调度/运行python脚本
【发布时间】:2022-01-17 02:16:19
【问题描述】:

我在 GitHub 存储库中有一个 Python 测试脚本,我希望每隔几个小时运行一次。现在,我知道我可以使用 Jenkins 来安排执行并让它们在我的机器上本地运行,但我的问题是如何在不需要打开机器电源的情况下执行此操作?换句话说,有没有办法在本地运行脚本并通过一些无头服务?我的公司确实使用circleCI,我会使用吗?

【问题讨论】:

    标签: python github jenkins continuous-integration pytest


    【解决方案1】:

    Jenkins 中的“cron”计划可让您按重复计划运行测试。此 Stack Overflow 问题的详细信息:Configure cron job to run every 15 minutes on Jenkins

    您还提到了 CircleCI,为此您可以在此处找到一些有关配置 .yml 文件的有用信息:https://stackoverflow.com/a/22028637/7058266

    由于您使用的是 GitHub,因此您也可以使用 GitHub Actions 执行此操作:How can I get Selenium tests to run in python with Github actions?

    您需要在 .yml 文件中设置一个 cron 计时(详细信息在 https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions 中):

    on:
      schedule:
        # * is a special character in YAML so you have to quote this string
        - cron:  '30 5,17 * * *'
    

    如果您需要更多帮助,我在几年前制作了一个视频,介绍如何使用 SeleniumBase 从 Google Cloud 在 Jenkins 上设置 Jenkins 以进行 Python/pytest Selenium 测试:https://www.youtube.com/watch?v=n-sno20R9P0

    (如果您只是在没有 Selenium 的情况下运行 Python/pytest 脚本,请忽略 Selenium 特定的部分。)

    【讨论】:

    • 谢谢。如果我走这些路线,脚本将在哪里执行?因为我不想让它在本地运行,因为我不想让我的机器开机。
    • 脚本将从托管您选择的 CI/CD 平台的服务器上执行,无论是 Jenkins、CircleCI、GitHub Actions 还是其他。
    猜你喜欢
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多