0

I am trying to start two processes from a Jenkins job using a Windows batch command:

REM start Selenium drivers if needed
cd "%WORKSPACE%\Uca.SeleniumTests"
start "" powershell -ExecutionPolicy unrestricted -file ./startDrivers.ps1

startDrivers.ps1

$isGeckoDriverProcessOn = Get-Process geckodriver -ErrorAction SilentlyContinue
if(!$isGeckoDriverProcessOn){   
    Write-Host 'Starting geckodriver'   
    Start-Process -FilePath "geckodriver.exe"
} 

#$startChromeDriver = (Get-Item -Path ".\" -Verbose).FullName
$isChromeDriverProcessOn = Get-Process chromedriver -ErrorAction SilentlyContinue
if(!$isChromeDriverProcessOn){    
    Write-Host 'Starting chromedriver'
    Start-Process -FilePath "chromedriver.exe" 
}

This works fine when run from a command prompt, but the processes are immediately killed when run from Jenkins in spite of trying to run in another session (start).

Jenkins slave is started from command prompt and I can see the process windows being shown for half a second. My feeling is that Jenkins is killing command line sessions and these processes along with it.

Question: How to execute a windows batch command in Jenkins that is not killed?

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
  • 1
    perhaps add `pause` at the end your batch file to see if you get errors.. It might be a syntax error with the path to the powershell script. I am unable to test this, no jenkins environment.. – Gerhard Jan 07 '19 at 17:58
  • @GerhardBarnard - yes, it makes sense. I cannot connect to work to try right now, but I will give it a try and come back. – Alexei - check Codidact Jan 07 '19 at 18:16
  • all good. let me know when you have tried it. – Gerhard Jan 07 '19 at 18:17
  • @GerhardBarnard - PAUSE is ignored by Jenkins (it outputs Press any key... , kill the process and goes to next step). However, I realized I am not asking the right question and provided an answer based on this.Thanks. – Alexei - check Codidact Jan 07 '19 at 19:27
  • Cool, glad my useless help actually helped a bit :) – Gerhard Jan 08 '19 at 06:27

1 Answers1

0

I realized that I am asking the wrong question and right one is: how to make sure that some processes used by Jenkins are long-lived?

It seems that Jenkins is designed to clean all running processes at soon as possible as per this question and PrcessTreeKiller:

To reliably kill processes spawned by a job during a build, Jenkins contains a bit of native code to list up such processes and kill them.

While the aforementioned question mentions a few ways to overcome this, it is clear the recommended way is to not spawn long-running processing via a job step, but outside of Jenkins (e.g. run a scheduled task to ensure the processes are running).

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164