How do I implement a deployment gate?

Hi! I’m looking to integrate Datadog Quality Gates, specifically the datadog-ci gate evaluate (https://docs.datadoghq.com/quality_gates/setup/#invoking-quality-gates) command, as a pre-deployment check in my workflow. My goal is to prevent deployments if the Quality Gate evaluation fails.

Current setup:

  • GitHub repository containing an SPA built with Vue and Vite.
  • Permanent branches include staging and production.
  • Netlify automatically triggers deployments when new commits are pushed to these branches.

Desired Integration:

I want to introduce a Quality Gate that will block deployments if the datadog-ci gate evaluate command returns a failure. I’m considering writing a GitHub Action for triggering deployments that would,

  1. Run the datadog-ci gate evaluate command.
  2. Depending on the result of the previous step, trigger a Netlify deployment using the Netlify GitHub Action: https://github.com/netlify/actions/tree/master/build

Is this approach the recommended way to implement a deployment gate?

P.S. I understand that someone with Netlify access could manually trigger a deployment, but that is an acceptable risk at the moment.

@shravan I’m unfamiliar with datadog so don’t know its requirements, but if it can be run on Netlify then you could adjust your build command to:

datadog-ci gate evaluate && {your-vite-build-command-e.g.-npm-run-build}

The documentation indicates that it “Fails if one or more blocking rules fail”, which would then prevent the rest of the build command from executing and Netlify from deploying.

This would have the advantage of preventing builds even if manually triggered by the Netlify UI.

However if you cannot get it to run on Netlify, or just don’t want to, then you could implement it as you’ve indicated.

Thanks for the reply. I don’t think datadog-ci would be available on any Netlify runner out of the box, so there’ll be an install step involved (@datadog/datadog-ci - npm (npmjs.com)). In fact, that is one of the reasons I’ve decided to go with Github actions. But the Netlify Github Actions workflows haven’t been updated in years, hence my hesitation to use them.

Let me know if you have any suggestions. Thank you!

@shravan If all it requires is that npm package to be installed, that’s no issue at all.

See: Manage build dependencies | Netlify Docs

Oh okay. Just to clarify, I’m trying to install datadog-ci as a global npm package so I call it before I run my app’s build command i.e. pnpm build. The doc link you shared seems to be explaining the process of adding dependencies to the app itself. Please let me know if I’m getting it wrong.

@shravan It should be no different than installing any other dev dependency.

As an example, vite is not naturally available in Netlify’s build image.

A package.json for a site using vite may look like:

{
  "name": "project",
  "dependencies": {},
  "devDependencies": {
    "vite": "latest"
  },
  "scripts": {
    "start": "vite",
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  }
}

The user sets their build command as npm run build, which in turn executes vite build

See how the instructions on the npm package page for datadog mention

npm install --save-dev @datadog/datadog-ci

This is a wildly fictitious example, but you may end up with something like:

{
  "name": "project",
  "dependencies": {},
  "devDependencies": {
    "@datadog/datadog-ci": "latest",
    "vite": "latest"
  },
  "scripts": {
    "start": "vite",
    "dev": "vite",
    "build": "datadog-ci gate evaluate && vite build",
    "preview": "vite preview"
  }
}

In Netlify you would set your Build command to npm run build

Oh awesome, thanks a lot! :slight_smile:

glad to hear you found a solution!

1 Like