Environmental variables limited to certain branches don't work during deployment

Referencing an environmental variable in the script part of a script deployment doesn’t work if I restrict the use of the environmental variables to particular branches (e.g., master). The problematic build is here.

If I remove the restricted environmental variables and create new ones with the same names but open to all branches, it works (see this build).


Note that using after_script to do the deployment using restricted environmental variables works (see this build).