Is it possible to manually build "remotely"?


I have checked on the documentation and I’m not sure it’s possible so I’m asking: Is it possible to manually run a build remotely (on netlify, not on my machine).

I would like to run “netlify build” with a custom context on netlify (because it’s super fast). I don’t know if it’s good but I have multiple context like: E2E, staging, production, … And I would like to test my react application on these 3 “api” environment (the api endpoint change, but also some other configurations)

Right now, I think I only can:

  • Build locally with a context
  • Let netlify build the app (and deploy) for me. But then, I can’t switch context (and the api endpoint)

Is there another solution?

I also would like to set a custom environment variable for a build, but I don’t think I can.

Could you confirm?

Thank you :slight_smile:

Not sure if this will help, but, one thing you can do to switch context is use branch deploy feature. You will basically have to manage multiple branches for your repo and keep a separate netlify.toml for each of those. In that, you can add separate values inside the branch deploy context. This might be difficult to configure since you’d have to use same folder in multiple branches, which according to me is not possible (maybe with symbolic links or something it is).

+1, very doable with branch-specific contexts!

And… env vars you say? :slight_smile:

Thanks for your anwsers :slight_smile:

Indeed it’s complicated with branch-specific. I thought “netlify build” would build my website remotely but unfortunately it takes the power of my CI and it’s slower than netlify (<3).

The problem with the second link you gave me @Pie, is that it says " assuming you are only trying to change headers or redirects. The rest of the file is read BEFORE your build — but those sections are read AFTER the build process.". But I need these env variable for the build :frowning:

I’m trying to “hack” a bit netlify here and right now, what I have done is a plugin with “onPreBuild” which read the process.env.INCOMING_HOOK_BODY (so i’m using build hook) that contains a “context” :smiley:. Then I overwrite some proces.env variables.

But I have a new problem now: How my CI knows that the deploy is finished? I’m connected with gitlab on it and I activated all the “Deploy notifications”, but my gitlab doesn’t seem to receive anything :frowning:

Right, the netlify cli is mainly geared towards local development, I think. So things like build will build locally. You could possibly figure out a way to use the API to trigger a build:, but I don’t have much experience doing that myself.

Maybe build hooks ( might help but again, it’s not exactly what you are looking for.

To look at the issue in a different perspective, what about triggering your CI from within a netlify build, instead? Is that something that would be possible?

Hi Dennis and thank you for your answer.

I finally did the “build + deploy” in CLI in my CI because for the moment our gitlab is self-hosted and we are migrating to a “cloud” one… It’s nice because we have E2E test that are running on the deployed environment.

Calling the CI from the build would be possible, but the API of gitlab is more complicated than the one from netlify :slight_smile: