How to change deployment based on GitLab instance

For reasons beyond my control, we are currently using two separate GitLab instances that each contain a copy of the repositories we work on. Commits go to both copies. The CI configuration is the same for both, except for the deploy stage. Is there a way to use a different deployment script based on what instance the CI is running on?

To illustrate this better, say I have gitlab.foo.com and gitlab.bar.com. Each contains a full copy of my project. When I push to gitlab.foo.com, I want deployment to use a different script than when I push to gitlab.bar.com. How can that be achieved?