I’m encountering a challenge with Netlify’s build process when pushing multiple commits quickly. Our goal is to deploy only “release” commits with updated app versions, sidelining intermediary ones. However, despite using an ignore script, both commits trigger builds, and unexpectedly, both appear to reference the latest commit.
Netlify Site Name:teams-react-prod.netlify.app
Why We Use the Ignore Script:
We employ a version bumping strategy where only specific “release” commits, which contain the updated app version. Our ignore script aids in this process by checking the commit message to determine if the commit is a “release” commit. Here’s a snippet of it:
const { execSync } = require("child_process");
const log = (msg) => console.log(`[ignore-script] ${msg}`);
log(`Checking if build should be ignored for commit ${process.env.COMMIT_REF}`);
const commitMsg = execSync(`git log -1 --pretty=%B ${process.env.COMMIT_REF}`)
.toString()
.trim();
const isReleaseCommit = commitMsg.startsWith("Release: ");
log(`Last commit message: "${commitMsg}"`);
log(`Is release commit: "${isReleaseCommit}"`);
// ... checks and process.exit(...)
Details & Screenshots:
Here’s a snapshot of the two commits/deploys:
main@8d76bf6
"Release: 2.1.6+4b6a7ae" # release commit
Today at 11:22 AM
Deployed in 5m 8s
main@4b6a7ae
"Add some logs to version bump action (#1793)" # intermediary commit
Today at 11:22 AM
Deployed in 5m 3s
The add some logs to version bump action should have the build ignored, and the Release: 2.1.6... should be built.
Given my ignore script, which uses the COMMIT_REF to get the latest commit message, I was anticipating Netlify to focus on the commit with the message Release: ... and skip the other one (4b6a…). However, when I dove into the deploy log for the 4b6a, it seems to be referencing the 8d76… commit:
Given the documentation regarding Netlify’s environment variable COMMIT_REF, this variable should be pointing to the 4b6a7ae commit instead of the latest one. Or am I missing something?
Hi, @kaisermann. The root cause here is that the commit that triggers the build is not necessarily the commit that gets built.
When a commit to a branch triggers a build we clone refs/heads/main (assuming the branch for the deploy is main). However, if you made other commits quickly after this, refs/heads/main pointer may reference a later commit in the same branch by the time the repo is cloned.
I’ve opened a support ticket about this and shared more details there. Please feel free to reply there or here, whichever you prefer.
I suspected this would be the reason. Would it be possible then to have access to an environment variable with the build that triggered the commit? If not, I would suggest adding some text to the Env Variables documentation saying that the COMMIT_REF is not necessarily the same as the commit that triggers the build.
I’m also going to paste part of the ticket answer as it can be meaningful for someone else:
I do see that the deploy information in the API does have the correct checksum but accessing the API during the build would be a far more complex workflow. There are strings that can be added to commit messages to prevent builds from running at Netlify. Those are documented here:
To summarize all this, the only way to filter the builds based on commit messages would be to query the API to get details about the deploy while it is running. While possible that would be a much more complex “build ignore command” workflow.
If there are questions about the alternate workflow or anything else related to this issue, please feel free to reply here (or to the forum thread) anytime.
I decided to attempt the “query the API” suggested approach and it indeed worked
However, as a bit of non-solicited feedback, I do have to say that I find it somewhat odd to have the commit_ref from the API pointing to a certain commit and the commit_ref from the environment pointing to another