Home
Support Forums

How to get branch subdomain in a branch build?

I have branch subdomains configured for my site, porter.sh. When I have a branch named v1, there is a corresponding subdomain v1.porter.sh. As part of my build, I need the final production URL for my site. For branch builds with subdomains, that would be something like “release-v1.porter.sh”, but I can’t find any environment variables that have that value.

I have tried $DEPLOY_PRIME_URL, but for branches it has the value “release-v1–porter.netlify.app” and doesn’t give me the branch subdomain. I have also tried $URL but that only gives me the root site domain, “porter.sh”.

Is there an environment variable with the branch subdomain or should I be writing bash to extract the branch name from the DEPLOY_PRIME_URL?

howdy @carolynvs ! :wave:

i wonder if instead of using a netlify specific env var to identify the branch, you could use the git branch name?

given that it always has to match?

1 Like

Thanks, Perry! I had missed that the branch name was available as an environment variable. That’ll work perfectly. :sparkles:

2 Likes

awesome! glad i could help :smiley:

1 Like