Build scripts fails via RTC build definition but passes when invoked manually.
I have a .CMD file which when run on build server, works perfectly fine.
Accepted answer
I believe this issue is similar to this post.
https://jazz.net/forum/questions/236871/how-to-specify-the-build-script-directory
Basically, if your script calls other scripts using relative paths, you need to make sure the current working directory is the correct one.
One other answer
From the information you provided, I could not see why the error is related to the environment variable. Is the full path of the perl script ".\YY\ZZ.pl" set by an environment variable?
In that case, you may add some debug in your build script to check if the environment variable is set properly. You can also add a build property in the build definition and configure the "Environment variables" in the "Command Line" tab of the build definition.