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

Article ID:220106267
1 minute readKnowledge base

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

Jenkins Agent Windows Service General
Jenkins Agent Windows Service Logon 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 (Adminsitrator below)

Jenkins Agent Windows Service Logon Specific Account

Then Maven correctly defines the user’s home as C:\Users\Administrator

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.