Starting a process from Azure deployment agent task

Tom Gutzler 21 Reputation points
2020-05-19T06:23:42.513+00:00

Hi,

I have configured my Azure release pipeline with a deployment group job that is targeting a pool of windows machines.
After successful deployment, that job is running a power shell script task which attempts to start a windows executable with GUI on the target machine. Then it waits for 1s and checks if the executable is running. I'm getting a valid process ID back in the log file of the deployment job.
But when I check on the PC after the release is complete I don't see the executable running and task manager shows no process with the logged process ID.
Is there something I need to do to make sure it keeps running when the agent has finished its work?

The agent is running as the same user which is logged on.

This is the power shell script

$p = Get-Process -Name $(Process) -ErrorAction SilentlyContinue  
if ($p) {  
  Write-Host "$(Process) is running with PID" $p.Id -Background Green  
} else {  
  Write-Host "$(Process) is not running - starting $(PathToExecutable)"  
  Start-Process -FilePath "$(PathToExecutable)"  
  sleep 1  
  $p = Get-Process -Name $(Process) -ErrorAction SilentlyContinue  
  if ($p) {  
    Write-Host "$(Process) is running with PID" $p.Id -Background Green  
  } else {  
    Write-Host "Could not start $(Process)" -Background Red  
  }  
}  
  

And an example log file

2020-05-19T02:12:57.7435760Z ##[section]Starting: Start Process Unless Running  
2020-05-19T02:12:57.7619447Z ==============================================================================  
2020-05-19T02:12:57.7619818Z Task         : PowerShell  
2020-05-19T02:12:57.7620096Z Description  : Run a PowerShell script on Linux, macOS, or Windows  
2020-05-19T02:12:57.7620357Z Version      : 2.165.0  
2020-05-19T02:12:57.7620622Z Author       : Microsoft Corporation  
2020-05-19T02:12:57.7620951Z Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/powershell  
2020-05-19T02:12:57.7621328Z ==============================================================================  
2020-05-19T02:12:59.4240091Z Generating script.  
2020-05-19T02:12:59.4987674Z ========================== Starting Command Output ===========================  
2020-05-19T02:12:59.5297125Z ##[command]"C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\azagent\A1\_work\_temp\97741594-232f-4de0-adeb-df1929e6c245.ps1'"  
2020-05-19T02:12:59.8622987Z <Process> is not running - starting <App.exe>  
2020-05-19T02:13:01.0336371Z <Process> is running with PID 11232  
2020-05-19T02:13:01.1572479Z ##[section]Finishing: Start Process Unless Running  

Also, sorry for tagging azure-virtual-machines when it's not about virtual machines but I just couldn't find a matching tag :(

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,960 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dave Patrick 426.1K Reputation points MVP
    2020-05-19T11:26:53.357+00:00

    QnA currently supports the products listed here (more to be added) Better to reach out to subject matter experts in dedicated forums over here.

    https://developercommunity.visualstudio.com/spaces/21/index.html

    https://developercommunity.visualstudio.com/spaces/22/index.html

    (please don't forget to mark helpful replies as answer)

    --------------------------

    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tom Gutzler 21 Reputation points
    2020-05-19T23:00:29.35+00:00

    Thanks, will repost there