Schedule run but only if new commits available

I have configured my circle ci to run on my master brunch every sunday. It works as expected. I also use pipeline with parameters and my ‘manual’ workflow when I need to bypass schedule and imiediatly execute build (e.g. some urgent fix)
I wonder, if there is a way to enhance my scheduled builds to run only if new commits available? for instance, the build has been scheduled once a week. It has been executed last week, no new commits this week, scheduler checks if latest commit has been built, if yes, no actions needed, if not, run schedule.

here is my current config:

version: 2.1

parameters:
  run_workflow:
    type: boolean
    default: false

jobs:
  build:
    ${my build commands}  
  
workflows:
  version: 2
 
  build_master:
    triggers:
      - schedule:
          cron: "2 1 * * 0"
          filters:
            branches:
              only: master
    jobs: &build_master
      - build

  build_master_manual:
    when: << pipeline.parameters.run_workflow >>
    jobs: *build_master
2 Likes

I have not tried it yet but I think something like this would work:

workflows:
  my-workflow:
      when:
        not:
          - equal: [ << pipline.git.revision >>, << pipeline.git.base_revision >> ]

Basically comparing the current build’s commit to the latest build’s commit and only executing the build if they are different.

1 Like

This does not seem to work to compare a pipeline variable string on the left and right (linter sees failure in config file). Any idea how can we compare if two string pipeline variables are the same?