How to schedule/run python script remotely using jenkins
I have a Python test script in a GitHub repo that I am looking to run every few hours. Now, I know I can use Jenkins to schedule the executions and have them run locally on my machine, but my question is how do I do this without the need for my machine to be powered on? In other words, is there a way to run a script not locally and through some headless service? My company does use circleCI, is that what I would use?
Solution 1:
A "cron" schedule in Jenkins would let you run tests on a repeating schedule. Details from this Stack Overflow question: Configure cron job to run every 15 minutes on Jenkins
You also mentioned CircleCI, and for that you'll find some useful information about configuring the .yml
file here: https://stackoverflow.com/a/22028637/7058266
Since you're using GitHub, you'll also be able to do that using GitHub Actions: How can I get Selenium tests to run in python with Github actions?
You'll need to set a cron timing in that .yml
file (details in 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 * * *'
If you need more assistance, I created a video a few years ago about how to set up Jenkins for Python/pytest Selenium testing on Jenkins from Google Cloud using SeleniumBase here: https://www.youtube.com/watch?v=n-sno20R9P0
(If you're just running a Python/pytest script without Selenium, just ignore the Selenium-specific parts.)