Changing deploy preview build settings based on branches used in pull request

Hello - I am a novice developer using netlify for the past 6 months.

My site code is hosted on GitHub and I have 3 primary branches - dev, stage and master.

When I create a pull request netlify allows me to use the ‘deploy-preview’ context in netlify.toml to control the build settings. So far so good and all works just fine.

But what if I wish to have different build settings dependent on the source or destination of the pull?

For example if I pull from dev → stage I would have one build configuration, but another config if I pulled from stage → master.

It appears netlify uses the same deploy-preview context in both cases and I see no way to change this except to manually update the netlify.toml configuration in the branch being pulled.

Another way to describe my issue: I am using jekyll as the build tool with a separate config file for production (master), stage and dev builds, controlled by branch contexts in netlify.toml. I would also like to be able to specify which of these configs is used when a deploy-preview is triggered depending on the source and/or destination of the pull

Thanks in advance for any help anyone can offer

///Paul

hi there @Roa_Music,

i think what you are referring to us a build context:

that should, if i am understanding what you are asking correctly, allow you to create different sets of settings :slight_smile: depending on the context you are aiming for.

Yes - build contexts do what I want and I am successfully using those already exactly as documented in the link you provided. But not all contexts support the new preview capability released this week allowing reviewers to provide direct site feedback.

That new feature appears to only be available after a deploy-preview build and those in turn can only be controlled by a single build context called deploy-preview. (Unless I’ve missed something)

Is there a way to generate different deploy-preview builds that doesn’t involve changing Netlify.toml ? Alternatively are there ways to force the new preview feature to be available on builds other than those generated via a deploy-preview build? (I’m presuming not given the way the feature is tied to pull/merge requests)

hi @Roa_Music - i just had a chance to check with the team who works on collaborative deploy previews, and it seems unlikely that this functionality will become available to build contexts other than the deploy-preview.

Hi - thanks for the info, though that was my expectation given the way the feature is implemented in the workflow.

So my original question still stands: Is there - or will there be - a way to set different build settings when generating a deploy preview that does not require me to manually update the deploy-preview context in Netlify.toml?

hi @Roa_Music -

can i ask some additional, questions ? I’m not quite sure we are able to interpret exactly what you are hoping to do, hence the slow reply! Could you explain what you are trying to accomplish in a different way, perhaps? :pray:

Are hoping that we will make CDP available on branch deploys instead of just deploy previews, or am I misunderstanding? thanks for clarifying!

1 Like

Hi Perry - Thanks for continuing to look into this.

As mentioned in my original post I am a relatively new Web designer and so there may be better ways of working. I’m open to ideas. But here is my current flow and what I am trying to do. Note I am the sole developer on this project for the moment.

My project repo has 3 primary branches:

  • master - my production release branch
  • stage - used to test with all optimisations, 3rd party features (eg comments, search indexing) enabled etc
  • dev - my primary development branch

Each of these 3 branches requires a different build configuration (eg to control what features are enabled on the site, or if optimisations are enabled) and I have these setup via named branch contexts in netlify.toml. This works well and I am easily able to generate builds for each of the 3 branches simply via git merges; dev merged into stage, stage merged into master.

But I would like to take advantage of the new deploy preview capability to allow others to comment on the site and provide feedback tracked in GitHub. To do that I need to slightly change my flow and use pull requests to merge code between the branches which then creates the necessary deploy preview. This makes sense but causes a difficulty as there is only one deploy-preview context that can be specified in netlify.toml as far as I’m aware.

What would be helpful is if there were multiple deploy-preview contexts I could setup - controlled for example based on either the source or destination of the pull request. eg if I create a pull from dev to stage one deploy-preview/build configuration context would be used, and another if I pull from dev to stage.

My work around today is that I must manually change netlify.toml to achieve the flow - updating the deploy preview context settings. I not expecting or requesting that preview builds be available to branch contexts, though that would be one solution in my case. I think the better option would be more flexibility around the settings for creating deploy-previews.

Unless there’s a better way to do this? Some alternative flow? I’d appreciate the advice if so