by Moe Ibrahim

How to get GitLab to do periodic jobs for you in under a minute

What would technology be without a computer doing periodic work?

Whether it’s your phone constantly checking your inbox for you, or getting timely alerts for weather or flight delays.

What about a bitcoin vs Canadian dollar price service, in just 56 seconds? No IFTTT, no Zapier, but no programming languages either — and no frameworks, no server or docker configuration, no Raspberry Pi, no AWS and no tests!

To make the example as universal as possible, we will only use 2 command lines:

  • one to GET the bitcoin price from an API
  • and another to POST it to another service.

Of course you can make this more useful by posting the price to Twitter, Twilio, Telegram, Slack and so on. But here we will simply post it to putsreq.com so we can inspect the POST request.

Then we will use GitLab-CI to schedule it to run everyday.

Level : All levels
Requirements : Any web browser

Let’s get you started :

  1. Create a free account at gitlab.com (20 seconds)

2. Create a new Project : Click on the New Project button to create a new repo, and in the name field type periodic-job or any other name. (9 seconds)

Then save it by clicking on Create Project (1 second).

3. Create a .gitlab-ci.yml file in this new project: Click on New File, copy and paste the following snippet into the .gitlab-ci.yml file, then click save (5 seconds)

test:
 script:
 - btc=$(curl https://min-api.cryptocompare.com/data/price?fsym=BTC\&tsyms=CAD)
- curl -i -X POST https://putsreq.com/wkDdMQWhaOyalisaIe49 — data ‘price=CA$ ‘“${btc//[0-9\.]/}”

These are basically two simple commands. Here we can go further and add

if [ $btc -ge 15000 -a $btc -lt 7000 ]; then

conditions, or even run a full bash script file, but let’s keep it simple.

Click on the Commit changes button, and this will trigger it to build and run.

4. Schedule it to run everyday: click on the CI/CD icon to expand the menu, and select Schedules to set up a name and a timer for your periodic job to trigger. (11 seconds)

click on New schedule button
Type in a name for the new schedule daily-bitcoin-price-job, select to run it daily then click Save
Your scheduled job has been saved

5. Congrats! You’re done. Go to to this link in putsreq.com to see it in action. (10 seconds)

This job will run everyday as long as your free 2000/month build minutes do not run out.

We haven’t even scratched the surface of what we can do with GitLab-CI — just think of all the possibilities of using it to create webhooks or connecting it to IFTTT and Zapier, which in turn would connect it to hundreds of services.

In the next article we will go through what we have just done, and how we can take it up a notch and create a webhook and use it to post to social media.

You can find the sample code here, and you can read the build logs here.