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:

  package = "my-plugin-name-here"

    inputOne = "xxxxx"
    secondInput = "yyyyy"

  package = "my-plugin-name-here"

    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?

Hi @alexrussell,

This is not currently possible. However we have a feature request about what you are precisely describing at

Stay tuned!

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