Yeah, as you found, the environment is the sh is only present during that run. It is just like dropping to a shell (or running another shell within a shell), running some things, and then exiting.
If you want to set them globally, you will need to set them in an environment block in declarative pipeline, or in groovy code. env.FOO = "BAR".
If you want to try to set something in the shell, and then get those values back into the pipeline, it gets a little harder. You can return just a value from a shell script and assign that to a variable. Or you can look at the pipeline utility steps plugin to suck things in from a file.