My VSTS Agent fails to start when configured as a service

Problem:

When I try and install my agent as a service with a user account it fails to start.

image

Even if I try to start it from services window it fails.

image

Solution:

Make sure the account has the “Log on as a service” right.

Explanation:

After configuring my agent with the following command my agent failed to start.

.\config.cmd --url https://<Account>.visualstudio.com --auth PAT --token <token> --pool default --runasservice --windowslogonaccount <DOMAIN\USER_NAME> --password <MyPassword> --work _work --agent <AgentName>

Windows services begin to run as soon as Windows boots regardless if anyone logs into the machines or not. Therefore, any accounts used as the service identity must have the right to log on as a service.  I needed to run my service as a user account because package management systems like NPM install packages per user.  Those packages cannot be used by the Network Service account so I configure my service based agents to run under a user account.

To correct this you have two options. Your first option is to do everything from the Services window.

  1. Press the Windows Key
  2. Type services
  3. Click Services
    image
  4. Right-click on VSTS Agent (<account.agent Name>)
  5. Select Properties
  6. Click Log On
  7. Re-enter your password
  8. Click Apply
    Windows will automatically grant the Log on as a service right to your account.
    image
  9. Click OK
  10. Click OK
  11. Right-click on VSTS Agent (<account.agent Name>)
  12. Select Start
    Your agent should start

Your second option is to manually grant the Log on as a service right using Group Policy.

  1. Press the Windows Key
  2. Type group
  3. Click Edit group policy
    image
  4. From the tree expand Windows Settings / Security Settings / Local Policies
  5. Select User Rights Assignment
  6. Double-click Log on as a service
  7. Click Add User or Group
  8. Enter the name of the user
  9. Click Check Names
  10. Click OK
  11. Click OK
  12. Return to command prompt where you configured your agent
  13. Type
    net start “VSTS Agent (<account.agent Name>)”
    Replace <account.agent Name> with your information
    Your agent should start
    image

Comments (3) -

  • Rodrigo de Souza Silva

    5/28/2018 4:58:37 PM | Reply

    Thanks a lot for the tutorial, it helped me a lot, I was with this problem for hours, I had already swept the whole internet behind a solution thank you very much.

  • Mike Devenney

    6/7/2018 3:07:23 PM | Reply

    Thanks man, I was fighting with hung builds for about two hours before I checked to see if the VSTS Service was running properly.

  • robert

    3/28/2020 5:12:23 AM | Reply

    Thanks a lot for the tutorial

Add comment

Loading