Finally, you need to create a build target for each of your enviroments. This can be done be selecting File -> New -> Target and selecting 'External Build System'
The best way to support multiple environments is to define a separate scheme for each one. Then add the relevant target as an external build step for each scheme ensuring that 'Parallelize Build' is disabled.
Why is this so complex? I found adding build pre-action in scheme settings working just fine:

Am I missing something?
Why is this so complex? I found adding

build pre-actionin scheme settings working just fine:Am I missing something?