AppiumDriverLocalService is not triggered programmatically in when running jenkins as a service

I have an appium project which runs perfectly in local system and jenkins perfectly. All of a sudden in Jenkins it started to throw the below exception

the main Appium script does not exist at ‘C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\npm\node_modules\appium\build\lib\main.js’

Earlier it was fetching automatically from

C:\username\AppData\Roaming\npm\node_modules\appium\build\lib\main.js’

Questions:

  1. Why there is a path change occurred? The only change that was done is modified the Jenkins to run as a service

  2. Setting the Node path and Appium JS path is not helpful and produced the below mentioned exception.

CODE:

 builder
 .withAppiumJS(new File(System.getenv("AppData") + "\\npm\\node_modules\\appium\\build\\lib\\main.js"))
 .usingDriverExecutable(new File("C:/Program Files/nodejs/node.exe"))

**Exception: ** the local appium server has not been started. The given Node.js executable:

Note:
Local Machine: Win 10
Jenkins Machine: Win 10
Appium java client: 7.3.0
Node latest version installed
Environmental variable path set for node and npm

that possible changes also PATH variable which now not visible to Jenkins.
compare it value before and after change.

Sure, I will check out that. But, when we are defining the Appium JS path and node path why it is not accepting?

possible this is not only paths needed. also needed android sdk, java, …

Now turned off the “Jenkins Run as a Service” and it is working fine. But I have to keep the Jenkins to Run as a Service only. In that case how can I avoid this issue which is fetching the system level path instead of user level.

  1. Should I change anything in Jenkins settings to fetch that from user level?
  2. Should I change anything in the code to take from the System level? - I have tried this withAppiumJS through Appium Builder but that does not work

you should inject environment variables into job.