Azure VM. The extension failed to execute: .agent file not found

Ruslan Burnashev 5 Reputation points
2023-05-17T11:03:20.85+00:00

We have Azure Virtual machine scale set working as pipeline agent pool. This error may appear on any new pipeline run. And after it happens once it happens on all subsequent runs.

Recreating agent pool or vm scale set fixes the issue. Restarting or reimaging vm do not help.

MicrosoftTeams-image

There are log files in C:\WindowsAzure\Logs\Plugins\Microsoft.VisualStudio.Services.TeamServicesAgent\1.31.0.0 folder with filenames like "RMExtensionHandler.6.20230515-024259":

[2023-05-15T02:43:00] [Agent Settings Helper]: Check if any existing agent is running from C:\AzurePiplinesAgent_Extension
[2023-05-15T02:43:00] [Agent Settings Helper]:       Agent setting file path C:\AzurePiplinesAgent_Extension\.agent
[2023-05-15T02:43:00] [Agent Settings Helper]:       Agent setting file exist: False
[2023-05-15T02:43:00] [Agent Settings Helper]: Check if any existing agent is running from C:\VSTSAgent
[2023-05-15T02:43:00] [Agent Settings Helper]:       Agent setting file path C:\VSTSAgent\.agent
[2023-05-15T02:43:00] [Agent Settings Helper]:       Agent setting file exist: False
[2023-05-15T02:43:00] reading last sequence number LASTSEQNUM file C:\Packages\Plugins\Microsoft.VisualStudio.Services.TeamServicesAgent\1.31.0.0\bin\..\LASTSEQNUM
[2023-05-15T02:43:00] Sequence Number: 6
[2023-05-15T02:43:00] Settings handler status to 'transitioning' (C:\Packages\Plugins\Microsoft.VisualStudio.Services.TeamServicesAgent\1.31.0.0\Status\6.status)

[2023-05-15T02:43:03] Reading config settings from file...
[2023-05-15T02:43:03] Reading handler settings from C:\Packages\Plugins\Microsoft.VisualStudio.Services.TeamServicesAgent\1.31.0.0\RuntimeSettings\6.settings
[2023-05-15T02:43:03] Found protected settings on Azure VM. Decrypting with certificate.
[2023-05-15T02:43:03] Read config settings from file. Now extracting inputs and doing basic validations.
[2023-05-15T02:43:03] Is Pipelines Agent
[2023-05-15T02:43:03] Using Protected EnableScriptParameters
[2023-05-15T02:43:03] Done reading pipelines agents settings.

[2023-05-15T02:43:04] Switch to TLS 1.2 to download files
[2023-05-15T02:43:04] Downloading files
[2023-05-15T02:43:04] Downloading agent zip file from https://vstsagentpackage.azureedge.net/agent/3.220.1/vsts-agent-win-x64-3.220.1.zip
[2023-05-15T02:43:05] Downloading enable script from https://vstsagenttools.blob.core.windows.net/tools/ElasticPools/Windows/17/enableagent.ps1

[2023-05-15T02:43:06] Running enable script
[2023-05-15T02:43:37] Enable script completed
[2023-05-15T02:43:37] EnablePipelinesAgent
2023-05-15 02:43:07Z PAT Token passed using env variable
2023-05-15 02:43:08Z Env variable deleted
2023-05-15 02:43:08Z Installing extension v17
2023-05-15 02:43:08Z URL: https://dev.azure.com/ArkkSolutions/
2023-05-15 02:43:08Z Pool: ArkkWindowsMultiAgent2
2023-05-15 02:43:08Z runArgs: 
2023-05-15 02:43:08Z interactive: False
2023-05-15 02:43:08Z agentDir: C:\agent
2023-05-15 02:43:08Z agentExe: C:\agent\bin\Agent.Listener.exe
2023-05-15 02:43:08Z agentZip: C:\agent\vsts-agent-win-x64-3.220.1.zip
2023-05-15 02:43:08Z agentConfig: C:\agent\config.cmd
2023-05-15 02:43:08Z Windows version: 10.0.20348
2023-05-15 02:43:13Z Windows edition: ServerDatacenter
2023-05-15 02:43:13Z runAsUser: True
2023-05-15 02:43:18Z Disable VisualStudio/VSIXAutoUpdater Tasks...
2023-05-15 02:43:22Z Disable Windows Update...
2023-05-15 02:43:25Z Disable Windows Telemetry (CompatTelRunner.exe etc.)...
2023-05-15 02:43:25Z Disable Misc. Scheduled Tasks...
2023-05-15 02:43:27Z Disable Azure Security Scheduled Tasks...
2023-05-15 02:43:27Z Setting WorkDir: C:\a
2023-05-15 02:43:27Z Unzipping Agent
2023-05-15 02:43:34Z Creating AzDevOps user
2023-05-15 02:43:34Z Adding AzDevOps to Users
2023-05-15 02:43:34Z Adding AzDevOps to Administrators
2023-05-15 02:43:34Z Configuring agent to run elevated as AzDevOps and as a Windows service
2023-05-15 02:43:37Z Finished
[2023-05-15T02:43:37] Error occured during Enable Pipelines Agent Error
[2023-05-15T02:43:37] System.Management.Automation.RuntimeException: .agent file not found. The agent was not set up correctly.
[2023-05-15T02:43:38] [ERROR] .agent file not found. The agent was not set up correctly.
[2023-05-15T02:43:38] {
    "Exception":  {
                      "ErrorRecord":  {
                                          "Exception":  "System.Management.Automation.ParentContainsErrorRecordException: .agent file not found. The agent was not set up correctly.",
                                          "TargetObject":  null,
                                          "CategoryInfo":  "NotSpecified: (:) [], ParentContainsErrorRecordException",
                                          "FullyQualifiedErrorId":  "RuntimeException",
                                          "ErrorDetails":  null,
                                          "InvocationInfo":  null,
                                          "ScriptStackTrace":  null,
                                          "PipelineIterationInfo":  ""
                                      },
                      "WasThrownFromThrowStatement":  true,
                      "Message":  ".agent file not found. The agent was not set up correctly.",
                      "Data":  {

                               },
                      "InnerException":  null,
                      "TargetSite":  null,
                      "StackTrace":  null,
                      "HelpLink":  null,
                      "Source":  null,
                      "HResult":  -2146233087
                  },
    "TargetObject":  ".agent file not found. The agent was not set up correctly.",
    "CategoryInfo":  {
                         "Category":  14,
                         "Activity":  "",
                         "Reason":  "RuntimeException",
                         "TargetName":  ".agent file not found. The agent was not set up correctly.",
                         "TargetType":  "String"
                     },
    "FullyQualifiedErrorId":  ".agent file not found. The agent was not set up correctly.",
    "ErrorDetails":  null,
    "InvocationInfo":  {
                           "MyCommand":  null,
                           "BoundParameters":  {

                                               },
                           "UnboundArguments":  [

                                                ],
                           "ScriptLineNumber":  163,
                           "OffsetInLine":  13,
                           "HistoryId":  -1,
                           "ScriptName":  "C:\\Packages\\Plugins\\Microsoft.VisualStudio.Services.TeamServicesAgent\\1.31.0.0\\bin\\EnablePipelinesAgent.ps1",
                           "Line":  "            throw \".agent file not found. The agent was not set up correctly.\"\r\n",
                           "PositionMessage":  "At C:\\Packages\\Plugins\\Microsoft.VisualStudio.Services.TeamServicesAgent\\1.31.0.0\\bin\\EnablePipelinesAgent.ps1:163 char:13\r\n+             throw \".agent file not found. The agent was not set up co ...\r\n+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
                           "PSScriptRoot":  "C:\\Packages\\Plugins\\Microsoft.VisualStudio.Services.TeamServicesAgent\\1.31.0.0\\bin",
                           "PSCommandPath":  "C:\\Packages\\Plugins\\Microsoft.VisualStudio.Services.TeamServicesAgent\\1.31.0.0\\bin\\EnablePipelinesAgent.ps1",
                           "InvocationName":  "",
                           "PipelineLength":  0,
                           "PipelinePosition":  0,
                           "ExpectingInput":  false,
                           "CommandOrigin":  1,
                           "DisplayScriptPosition":  null
                       },
    "ScriptStackTrace":  "at EnablePipelinesAgent, C:\\Packages\\Plugins\\Microsoft.VisualStudio.Services.TeamServicesAgent\\1.31.0.0\\bin\\EnablePipelinesAgent.ps1: line 163\r\nat Enable, C:\\Packages\\Plugins\\Microsoft.VisualStudio.Services.TeamServicesAgent\\1.31.0.0\\bin\\enable.ps1: line 443\r\nat \u003cScriptBlock\u003e, C:\\Packages\\Plugins\\Microsoft.VisualStudio.Services.TeamServicesAgent\\1.31.0.0\\bin\\enable.ps1: line 480\r\nat \u003cScriptBlock\u003e, \u003cNo file\u003e: line 1",
    "PipelineIterationInfo":  [

                              ]
}
[2023-05-15T02:43:38] Settings handler status to 'error' (C:\Packages\Plugins\Microsoft.VisualStudio.Services.TeamServicesAgent\1.31.0.0\Status\6.status)

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,563 questions
Azure Virtual Machine Scale Sets
Azure Virtual Machine Scale Sets
Azure compute resources that are used to create and manage groups of heterogeneous load-balanced virtual machines.
363 questions
{count} vote

1 answer

Sort by: Most helpful
  1. deherman-MSFT 35,556 Reputation points Microsoft Employee
    2023-05-18T18:21:10.5766667+00:00

    @Ruslan Burnashev

    To troubleshoot this, we're going to enable a free, one time technical support ticket. Please email the following to AzCommunity@microsoft.com and we'll get back to you promptly:

    • Subject: "Attn: deherman - "

    • Email body: Your Subscription ID

    • Email body: A link to this thread so we can validate and expedite the request

    If you don't receive a response within 24 hours, please reply to the thread so we can investigate.