Home
Support Forums

Multiple contexts for single branch

Hi there!

I’m currently setting up my workflow for https://sursen.netlify.app/ and I have some questions regarding multiple contexts for the same branch.

What I want to achieve is basically have two environments based on my main branch. The first should be a staging env, which will be deployed automatically, and the other should be our production env, which will be deployed manually from the netlify ui.

The staging could either be accessed through a custom domain or the netlify domain, that’s not a pressing issue. The production env will be accessed through our custom domain.

The two environments will be targeting two different versions of our backend (currently set through env vars in netlify.toml).

Does anyone know if this is possible? It feels like I’m either missing something obvious, or trying to do something fundamentally against the netlify way (e.i. breaking 1 branch = 1 behaviour).

Thanks in advance
Lasse

@Lasse-Fisker Welcome to the Netlify community.

Does this help?

Hi @gregraven, thanks for the reply

Unfortunately I don’t think so. I cannot see anything regarding multiple contexts on a single branch? (or how to achieve the setup specified above).

Hey there, @Lasse-Fisker :wave:

Thanks so much for reaching out, and welcome to the Netlify Forums :netliconfetti:

This is a good question. At this time, having multiple contexts on the same branch is not possible. You can read more about contexts and file based configuration in the Netlify docs!

+1 this would be great for a hugo site (one context builds drafts while another doesn’t). See more in my SO question here.

A hacky way to achieve this could be to use GitHub Actions.

You can commit to your repo with [skip netlify] anywhere in the commit message and add some text regarding what to context you wish to use → You can use something like ${{ github.event.head_commit.message }} to read the commit message and the context from it → edit the netlify.toml in your repo to force it to use a specific context like:

[build]
  context = "foo"

# context-specific settings can exist all the time

Finally, in the action itself, release another commit to your repo with the correct netlify.toml file and do not include [skip netlify] in your commit message this time.

Netlify will read the required netlify.toml file.