Commit_ref is null if the deploy was via a build hook

I’m writing a plugin for Statamic CMS, and want clients to be able to deploy their site via the control panel, but only if the latest automated commit from their server is different to the one their site is running.

So I’m able to trigger builds easily with the build hook I created, and I can get the site’s information using the Netlify API, but the commit_ref is always null if the build was triggered via the build hook. Is this intentional? It is directly linked to the branch (currently populated with ‘staging’), so I can’t think of a good reason why this would intentionally be null?

I’m not certain, but it’s possible that it’s because the same commit was used for the build after deploying the same thing again. For me at least, it’d be very helpful to have this information, as it’s still relevant.

Hi @davidsneal and welcome to our community!

Yes, $COMMIT_REF and other git-related variables will be null unless the build is triggered directly from git. We do clone the repo - so you can use commands like git status etc, to check what commit is in use. Some more advanced workflow around skipping builds based on git details are demonstrated in this thread, which you’ll probably find interesting.