Context-based build plugin config

I was trying today to get a certain build plugin only “activating” on a branch deploy/deploy preview (i.e. not in the “production” build). However, because all examples for netlify.toml build plugins shows it as a “global” thing I have had to “work out” the toml for myself. I think I have it right, but both netlify build --dry --context=branch-deploy and a proper branch push deploy log don’t show my plugin being used. If I use the “standard” [[plugins]] section name I can see it in the build dry run output.

Here’s the netlify.toml I have crafted:

[[context.branch-deploy.plugins]]
  package = "my-plugin-name-here"

  [context.branch-deploy.plugins.inputs]
    inputOne = "xxxxx"
    secondInput = "yyyyy"

[[context.deploy-preview.plugins]]
  package = "my-plugin-name-here"

  [context.deploy-preview.plugins.inputs]
    inputOne = "xxxxx"
    secondInput = "yyyyy"

Upon further digging, I have a feeling that this is because [[plugins]] is “global” in the netlify.toml file, but when you use [context.xxxxx.some-key] you’re actually setting the key as if it were inside the global [build] section in the netlify.toml file. Is that right?

Either way, is there a way to use a build plugin in one context but not another? Or use it in all, but specify different inputs depending on context?

1 Like

Hi @alexrussell,

This is not currently possible. However we have a feature request about what you are precisely describing at Allow context sensitive build plugins config in netlify.toml · Issue #1169 · netlify/build · GitHub.

Stay tuned!

1 Like

Aha, brilliant. Thanks @ehmicky.

I think I can “hack” it for the time being by using multiple sites (though they all deploy from the same GH repo) and simply not having a specific env var specified in one of the sites (the plugin lukcily requires an env var for a secret).

I have thumbs upped and subscribed to the GH issue.

1 Like

I just wanted to plus one this as it would be very useful for our team as well. In our case it is related to this other thread (Automatically deploy branches that match name pattern - #22 by knoxjeffrey) . We are running

[[plugins]]
  package = "netlify-plugin-chromium"

but don’t need this plugin to run on our CMS build because we won’t be running tests. There are also a few other plugins that I can see this being useful for.

1 Like

This has been implemented! :tada:

More information in this comment. Please let us know if this works as expected.

1 Like

This feature is now officially released!

1 Like