According to google's own docs, this should work.
> You can prevent a page from appearing in Google Search by including a noindex meta tag in the page's HTML code, or by returning a noindex header in the HTTP response.
Source: https://developers.google.com/search/docs/advanced/crawling/...