Forum Discussion

Ravikaanth's avatar
Ravikaanth
Contributor
11 months ago
Solved

Can't trigger TestExecute through Task Scheduler

I am trying to trigger TestExecute by using a .bat file through Task Scheduler. When I try trigger .bat file manually TestExecute triggered successfully. But if I try to trigger by using Task Scheduler the status is changed from Ready to Running, but we can't see anything in the background. Please check below screenshot.

 

Below code is the .bat file, Please verify it.

 

Echo off
cd "C:\Program Files (x86)\SmartBear\TestExecute 15\Bin"
start "" /wait "C:\Program Files (x86)\SmartBear\TestExecute 15\Bin\TestExecute.exe" "C:\Users\ravikaanth.ns\Documents\MB_Automation\TestProject2\MBAutomation1.pjs" /run /project:"MBAutomation1" /unit:"CampaignReadProd" /routine:"readCampaign"

 

 

 

  • I've just ran the same, these are the results. Also, TC has generated log files too.

    My batch file has only this command,

     

     

    start "TestExecute" /wait "C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin\TestExecute.exe" "C:\Sandbox\TestComplete\Project Flow\Project Flow.pjs" /run /exit /DoNotShowLog /project:"TestProject2" /ExportLog:"C:\Sandbox\Log\TestProject2\index.html"

     

     

    And task schedular

     

     

    How are you running your Task? Is this on your local machine?

43 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I'm determine to solve your issue - we've established that Task Scheduler works. After asking questions, I've realised you are using Agent.Listener, and this is what is causing you issues via Task Scheduler.

    Just to clarify and for my understanding. When the VM is restarted, it automatically logs into the VM using account 'automation.user' and you want the Agent.Listener to start as an interactive process (and not background process). So that you can run the automation via CI/CD i.e. Azure DevOps, and would also like to run the automation via Task Scheduler at a given time?

    I hope this is correct? 

    ...and I'm getting to the point on giving up with this new forum!

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    GREAT!

    On your Windows 10 environment, press the Windows Logo key + R, to bring up the Run dialog.

    Type in shell:startup, followed by OK. It should take you to the Startup folder of the user.

    Copy and paste the shortcut to the run.bat from the file location to the Startup folder.

    Restart the VM, you should then see the Agent.Listener running, when reconnected to the VM.

    You can then create a task to schedule your TestExecute.

    • dhundley's avatar
      dhundley
      Regular Contributor

      when we installed the agent on the VM we configured it for auto login so it already does start up automatically following a VM restart. i'm not sure from where the "auto" part originates from because there is nothing the typical startup folder on that VM

       but the agent always gets start following a restart. that's the way it's always been so i don't see how that will change what's going on with my task scheduler issue

  • dhundley's avatar
    dhundley
    Regular Contributor

    i might be onto something. because you made me think more about that auto login feature i did a little more research to discover where (since it wasn't in the typically windows startup location) does that auto-login originate. i searched the registry for "run.cmd" and found this piece of string data for the VSTSAgent

    C:\Windows\system32\cmd.exe /D /S /C start "Agent with AutoLogon" "C:\Agents\run.cmd" --startuptype autostartup 

    i'm betting that if i use this string in either the scheduled task or a bat file (or possible a powershell script) at the point in my process where i want to restart the agent after it has been closed, it will start it up the right way. i will let you know how it turns out

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You already have an agent that automatically starts-up? Which is configured as a background process, that you want to change to interactive process?

    To change the agent to interactive process, you need to reconfigure the agent. For example,

     

    • dhundley's avatar
      dhundley
      Regular Contributor

      i finally have it working. my scheduled task points to a bat file that runs a powershell script with the verb runas to elevate the permissions and in the powershell script, i have this code that successfully bounces the azure agent and keeps it in the Apps section of Task Manager. Thanks for all your help. 

      if (Get-Process -Name Agent.Listener -ErrorAction SilentlyContinue) 
      {
        echo "Azure Agent is running. Stopping Agent"
        Stop-Process -Name 'Agent.Listener' -Force
        Start-Sleep -Milliseconds 10000
        if (Get-Process -Name cmd -ErrorAction SilentlyContinue) 
        {
          Stop-Process -Name cmd
        }       
        Start-Sleep -Milliseconds 150000
      }
      echo "Starting Azure Agent"
      $command = 'start "Agent.Listener" "C:\Agents\run.cmd" --startuptype autostartup'
      Start-Process 'cmd' -ArgumentList "/D /S /C $command"

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    So you are killing the existing Agent.Listener, and then starting it back up. Why is it necessary to kill the process?

    I don't understand the reasons for doing this!?

    • dhundley's avatar
      dhundley
      Regular Contributor

      several reasons. why is it sometimes necessary to reboot your workstation? usually it's because it's stuck on something. we noticed our agents were getting multiple agent connect error/reconnected messages for no apparent reason 

      and at other times we couldn't figure out why a particular pipeline would indicate it had been queued but wasn't getting started but, as soon as we would bounce the agent, it would kick off.  we have some pipelines scheduled to start at 3am so, why not bounce the agent about an hour before that to make sure it's a fresh, unstuck, copy?