I have a new version of the site in a different repository, so I changed the build settings to point to the new repository, and all seemed well. However, I have just noticed that all the (20+) environment variables that I previously had configured have disappeared. Some of these were quite important and not trivial to recreate (access tokens and such).
Is there a way to restore the previous environment variables from before the build repository was changed?
Hiya @CamLAPC and sorry to be slow to get back to you!
Unfortunately, no - we donāt save those in any way (unless you created a new site, and the old site is still there, and you can still see the variables on it to copy and paste between).
Hmm. I just tried to reproduce this to inform the report to the docs team, and couldnāt - my variables remained in place after I edited my repo settings (linked to a different repo). Could you tell me in more detail the steps you took that resulted in the loss?
I went to the Netlify App admin for the site (in my case, Netlify App)
I went to the Build & Deploy section
I hit āEdit Settingsā
I hit āLink to a different repositoryā
I went through the āconnect to providerā/linking process (Iām using Bitbucket for both the old and new repositories)
I configured the build settings (branch, build command, publish directory). Note that these did NOT seem to retain my previous settings, which seems reasonable given it is an entirely different repository. Also, both the old and new repositories have a netlify.toml that overrides the build command and publish directory anyway.
I believe I clicked āNew Variableā in the advanced build settings, but did not actually add any variables (because I thought they would come through from the previous configuration)
I hit the deploy site button
Then I had a bit of a panic since I had not seen the āoldā env variables listed, cancelled the deploy, and went over to the environment page and saw that they had in fact gone.
Hope that helps! I will try to reproduce on my end as well.
@fool Ok, I have been able to reproduce it, and it seems the specific thing that triggers the clearing of the environment is clicking the āNew Variableā in the advanced build settings when changing the repository. As long as that option is NOT clicked, the environment is retained. However, if it is clicked, even if no actual variables are added, the previous environment variables are removed.
I guess this raises all kinds of interesting questions about how this should be handled, i.e. if new variables with the same name should automatically replace existing ones, but old ones should be merged in, and so on, which is probably why the existing behaviour is simply to remove the previous environment completely.
Regardless, it seems counter intuitive to me to have the existing variables either be invisibly kept or lost depending on whether you enter some new ones during the repository change, or even just hit the button to add new ones without actually doing so.
Wow, thank you for the very thorough report! Iāll get a bug filed; I donāt think that is intended (I think they should always be saved, even if you add a new one!)