Need to scope before_deploy and after_deploy to a single deployment provider

I have a travis build that contains a deploy step with two providers (bintray and releases). I need to execute a before_deploy and after_deploy step only for the bintray provider, but unfortunately they are run before and after EACH deployment provider.

How can I configure my before_deploy and after_deploy steps so they run only for the bintray deployment? If there isn’t a way to do this explicitly, is there some way that I could determine within my after_deploy step which provider is being processed? For example, if I could somehow set an environment variable within the bintray deploy step, then I could check for that in the after_deploy step.

Thanks in advance for any help!

Currently, the only way seems to be to set a flag variable and use it to skip the code at later invocations:

Previous discussion on this topic: