@iamskok, if you are looking to test if your script is being run in the Netlify build image/environment itself, then one great way to do this is by looking for the environment variable NETLIFY=true. For example:
if (process.env.NETLIFY === 'true') {
<do something Netlify specific here>
}
We set this environment variable in the build image specifically so CI/CD scripts can make conditional rules/tests for our build environment.
I hope this will meet the requirements for this use case and, either way, please feel free to follow-up with additional comments or questions here. We’re happy to discuss this further.