DEV Community

Ankur Sheel
Ankur Sheel

Posted on β€’ Originally published at ankursheel.com on

3 1

Using Azure Pipelines to deploy a gatsby site on a schedule

In an earlier post, I showed how to use azure pipelines to build a gatsby site and deploy to netlify. But it was slightly limited. A live build was deployed only when a push was made to master. There was no way to have scheduled posts go live automatically.

There are 2 ways to approach this problem.

  1. By using an AWS Lambda or Azure Functions. This is what I had initially and you can see the codehere.
  2. By adding a new azure pipeline which runs on a schedule.

In this post, I will be using azure pipelines to deploy the site daily.

Note: We will be using the template files created in the Deploying a Gatsby site to Netlify using Azure Pipelinesso I would suggest reading that first. Go on, I will wait.

Adding a new pipeline to schedule posts

Good, you are back.

Let’s create a new file azure-pipelines.daily.yml.

name: 'Daily Release'

schedules:
    - cron: '0 14 * * *'
      displayName: Daily build
      branches:
          include:
              - master
      always: true

trigger:
    batch: false
    branches:
        exclude:
            - '*'

pr: none

variables:
    - template: azure-pipelines.vars.yml

jobs:
    - template: azure-pipelines.common.yml
      parameters:
          deployScriptParams: '--prod'
          netlifySiteId: $(netlify.siteId)
          netlifyToken: $(netlify.token)
          message: 'Daily build'
  1. name : The name for this pipeline.
  2. schedules : The schedule on which the pipeline should run.
    1. cron : The cron syntax defining the schedule.
    2. displayName : The display name for the schedule.
    3. branches : Include only the master branch so that only the master branch is built and deployed.
    4. always: true : Always run the pipeline.
  3. trigger : Conditions for running the pipeline for when a push is made.
    1. branches : Exclude all branches so that the build is not triggered for commits on any branch including_master_.
  4. pr: none : Disable triggering the pipeline for when a PR is opened or changes pushed to an open PR. master.
  5. variables : We set a template file to get the environment variables.
  6. jobs : The jobs to run.
    1. template : Use the job template created in azure-pipelines.common.yml.
  7. parameters : The parameters to be passed to the job template
    1. netlifySiteId : The site ID from environment variables.
    2. netlifyToken : The token from environment variables.
    3. message : The message is hardcoded to Daily Build.

Gotchas

  1. The cron syntax is mm HH DD MM DW. You can find more details about the supported syntax here
  2. The timezone for schedules is UTC so the build times need to be adjusted accordingly.
  3. Don’t forget to set always: true. If you have it set to false, a build might not be triggered if you are schedulingposts a few days in advance.

Conclusion

With this setup, I can write posts and schedule them to go live in the future.

πŸ‘‹ While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay