After upgrading to Azure DevOps Server 2019, automated pipeline builds are failing at the NuGet restore step showing:
Error: Error: unable to get local issuer certificate
Packages failed to restore
Microsoft's documentation states that the build agent running on Windows uses the Windows certificate store, so I have checked that the required certificates are installed correctly on the build server, however it is still failing.
There are many questions with similar symptoms but not the same cause. After investigation, I have found the solution to this but I didn't spot anything on this exact issue so I will post an answer that will hopefully save somebody else some time!
It turns out that the Azure DevOps build agent is using a version of Node.js that doesn't use the Windows Certificate Store.
The solution required is to export a copy of your server's TLS Certificate's root CA certificate, in PEM format, and using either a system environment variable called NODE_EXTRA_CA_CERTS
or by using a Task Variable called NODE.EXTRA.CA.CERTS
or NODE_EXTRA_CA_CERTS
whose value points to the exported PEM certificate. This way, this older version of NodeJS will pick up that certificate, thus being able to validate the certificate chain to your server.