Home
Support Forums

Netlify build based on different source branch

Hi,
I have a use case with Netlify which I’m not sure how to solve.
I have a Jekyll github repo which contains a branch (let’s call master), and wish to have source branches for different languages. The different languages will use different config files, and I want to trigger different builds based on the source branch.

My issue is, how can i get Netlify to build a site based on the source branch when I merge to master while still having staging and preview builds? Or exclude source branch from running for a specific app?
Right now, I have 3 app set to the master branch, master is set to not auto publish, and a DE and FR app with auto published enable. I have DE and FR listen to PR to the master branch, but when i make a PR, both DE and FR app are running the CI.

Expected Workflow:

  1. Content gets translated and creates a language branch (ie FR and DE).
  2. I now make a PR that merges FR to master.
  3. After the PR is created but before it’s merge, I want Netlify to create a preview deployment using custom build command, ie bundle exec jekyll b --config fr.yml
  4. Ideally this will create a preview app, and sends that info back to the PR.
  5. PR is approved and merge, I now want to deploy just the FR language to an new app.

At the same time, I might have a German(DE) version PR that I would make a PR to merge, and I want that to also generate a separate Preview app using a different build command and config file ie bundle exec jekyll b --config de.yml.

Current Workflow:

  1. PR from DE to master or FR to Master causes both Apps to run when i only want their respective apps to build.

It mostly works, except any PR to master will trigger both the DE and FR app to build and i only want a specific one to run.

Thanks in advance

Here’s what i’m currently trying for reference:

  • Set an environment variable in the App for language branch to check for
  • use Netlify build ignore option to check against the PR
  • If source branch matches build ignore variable, cancel build

Will probably also need some logic to allow custom PR, so might check for a prefix first, and prefix all language branches with it ie LANG_FR and LANG_DE

Hey there,

Not sure that I follow along.

  1. I now make a PR that merges FR to master.

This doesn’t make sense to me as then your master will be focused on one language. Can you elaborate?

What URL should the ‘master’ branch be served from? Is ‘master’ an English branch? Is ‘master’ just used for maintaining shared config?

Hi,
Thanks for replying. I want the master to contain all the languages, but only have Netlify build my PR based on what is the source branch.

Here’s my file structure in github if it helps:

|- config.yml
|- config_fr.yml
|- config_de.yml
|- en/docs
|- english docs content
|- fr/docs
|- french docs content
|- de/docs
|- german docs content

I want each Netlify app to only build and deploy a specific language if it’s coming in from a foreign language branch ie lang_de or lang_fr.
So if i make a PR to merge from the lang_de to master, it’ll run a jekyll command like jekyll build --config_de.yml and create a staging app for de.
if i merge lang_fr to master, it’ll run a jekyll build --config config_fr.yml and create a straging app for fr.

If it’s not from a language branch (ie english), then it’ll just run jekyll build --config config.yml.

A reason why i want a different app for each language is that normal changes will mostly be in english and i don’t want the fr or de app to be build. If a french changes are made, i dont want the english or german app to be built.

Some other reason is we want to keep the languages in the same repo so that code changes will reflect all languages, we can have language specific pre-build process and reduction in overall build times.

I’m currently in the process of using the build ignore, curl and env variables to work around this.

Thanks

Thanks for the context. I think the best thing for your use case would be a bespoke build plugin. The benefit of this is that you can run the plugin before your build command, ensuring that the correct assets and config files are gathered before you run the build. It’ll need some thought but it could prove to be very powerful!