Maven jobs are using the root of the drive c as user home when the agent is launched as a windows service

1 minute read

Issue

When building a Maven job on a windows agent configured as service the user.home java system property is pointing to c:\ thus Maven is looking for user’s settings under c:\.m2\settings.xml, c:\.m2\security-settings.xml and it is storing the local repository in c:\.m2\repository\.

Environment

  • Jenkins

  • Jenkins LTS

  • CloudBees Jenkins Enterprise

  • Maven Job

  • Windows agent launched as service

Resolution

When a Jenkins agent is installed on windows as a service it configured to run as Local system account

This isn’t a real account on the server, that’s why Maven defines the user’s home (user.home java system property) as c:\

If you reconfigure your service to be launch with a real account, then Maven correctly defines the user’s home as C:\Users\USER_NAME

To properly manage your Maven settings accross agents it is recommended to use the Config File Provider Plugin which allows to centralize the management of these configuration files in your controller and to automatically deploy them in your agents to let Maven use them transparently.