Build in external CI struggling to use a custom branch subdomain

Hello,

Sitename: quillinteractive.netlify.app

Having a bit of a problem getting custom subdomains working for our use case. We need to use a custom subdomain because requests to all our backend services require CORS authentication and it’s not deemed secure enough to add netlify.app to our allowed origins. We use Netlify to manage DNS records.

We have had this working when using Netlify for the build step by doing the following…

  1. When a PR created in Github, use a Github action with the Netlify API to check to see if a build hook exists for that branch to trigger the build, and if not, create one and trigger it immediately.
  2. Check to see if a DNS record exists for that branch and if not, call the Netlify API to create 2 DNS records one for NETLIFY type, and another for NETLIFYv6 type, with the hostname as the desired subdomain (i.e i-am-a-branch.quilltest.com) and the value as the created netlify url. (i-am-a-branch–quillinteractive.netlify.app). This was done to replicate what happens on the webapp when creating a branch subdomain.

This has been working fine for us.

Recently, however, I’ve been trying to shift the build step to happen during a Github Action rather than on Netlify, so that our developers can get increased visibility of build errors and, as we are using a monorepo to build multiple sites, give us a little more granular control over what gets built and when (cancelled builds appearing as failed was starting to cause us to miss actual failures, but that’s a different issue).

To do this, our steps are now the following…

  1. When a PR is created in Github, trigger an action to build the package and deploy it to Netlify using the netlify cli with an alias of the branch name.

Example: npx netlify-cli deploy --message="I4 Webapp Test Deploy from GitHub for the branch ${{ github.head_ref }}" --dir=projects/i4-webapp/build --alias=${{ github.head_ref }}

  1. Then do the same step 2 as above - checking for existing records and using the API to create the 2 records.

When I do this, the build completes and gets successfully deployed to i-am-a-branch–quillinteractive.netlify.app (in as far as that url returns the expected CORS errors). I can also see that the DNS records have been created as expected in Netlify webapp.

However, when trying to visit the custom subdomain url ( i-am-a-branch.quilltest.com) it consistently responds with ‘Not Found’.

I have also tried to do step 2 as creating a CNAME and ALIAS record instead of the NETLIFY records, but all resulted in the same error. DNS propagation checks using dnsmap.io against either the CNAME, ALIAS and A records for the custom subdomain all seem to return as expected too.

At a bit of a loss here? Is there some magic going on behind the scenes when a branch is built on netlify servers that allows the mapping to work that I can’t replicate when building on Github?

Branch subdomains are only possible with builds that we complete in our CI. You can set a build “to a branch” via CLI, but it will not be a “real” branch, usable as a branch subdomain, and you’ll see the “Not Found” message.

Sorry I don’t have better news for you today!

Thankyou for the reply.

Am I right in thinking that this would be possible if we didn’t use Netlify to manage our DNS records?

Nope! The problem is not in DNS. The problem is that the CLI’s “branch” deploys are not real branch deploys in our system - real branch deploys (that you can use for a split test, or a branch subdomain) are created within our CI, not deployed via CLI.

Shame. Thankyou for letting me know.