All Articles

Custom Cron Job Interval in Travis CI

travis ci cron job setting


Cron job interval in Travis CI only allows daily, weekly and monthly. There’s no option to run a cron job that runs multiple times in a day. In this tutorial, I will show you how to have a custom cron job interval using Node.js


Travis CI has an api to trigger builds with a POST request. What if I could utilize this by creating a cron job in node.js and call this api with my custom interval?

To get your API authentication token, go to user settings

api authentication key

According to the docs, the request url should be like this

where travis-ci is the owner and travis-core is the repository name.

Let’s say my repository name is foo. My url should be like this

With that out of the way, let’s proceed to the Node.js code


I’m going to use node-cron library for the cron job because it is very easy to use.

Run this command first to get the required libraries.

npm install node-cron axios

Create an index.js or name it whatever you want. Write ( or copy paste ) the code below

const cron = require("node-cron");
const axios = require("axios");
axios.defaults.headers.common['Authorization'] = 'token YOURAPIKEY'; // this is for tutorial purposes only. save this in your env variables! Best practice is don't commit your API keys!
axios.defaults.headers.common['Travis-API-Version'] =  '3';['Content-Type'] = 'application/json';
const payload = {
"request": {
"branch": "master"
cron.schedule("0 0 */4 * * *", function () {

Check out the node-cron github to see the syntax for the schedule.

Hope this helps. If you have a better way to do this, please do let me know!