How to Schedule Cron Jobs in GitLab to Automate Netlify Builds for 11ty Blogs

Learn how to schedule cron jobs in GitLab CI/CD to automate daily Netlify builds for your 11ty blog. Step-by-step guide with examples and pipeline setup.

I have used GitLab Actions in the past to build static sites, but it never occurred to me that the same CI/CD pipelines could be leveraged for scheduling cron jobs.

Recently, I built this blog using 11ty and hosted it on Netlify. Netlify automatically rebuilds the site whenever I push changes to the repository. These changes might be because I wrote a new blog post, updated the design, or made some other modifications.

Since I started displaying the "most read" and "recently trending" posts on the blog, I began wondering if I could trigger a Netlify build daily so these sections would update automatically.

To achieve this, I utilized Open WebUI alongside GitLab's pipeline scheduling functionality. Here are the steps I followed:

  1. Create a new repository.
  2. Add a .gitlab-ci.yml file.
  3. Set up a pipeline schedule at:
    https://gitlab.com/jjude/crons/-/pipeline_schedules for the time you want it to run.
  4. Add any necessary variables you want to pass (in my case, NETLIFY_HOOK).

And that's it—you now have a cron job running on GitLab!

Here's the script I used to trigger the Netlify build:

trigger-netlify:
  image: curlimages/curl:latest
  only:
    - schedules
  script:
    - curl -X POST -d '{}' $NETLIFY_HOOK

This script will run exclusively on the pipeline schedules you configure (as opposed to being triggered during repository commit or push events, which are typical for static site builds).

Here's an example of how my pipeline schedule looks:

Published On:
Under: #11ty , #code