Metarunner created with Powershell hangs at the start of Powershell

Hello TeamCity Support, 

I have a metarunner created with Powershell as follows:
------------------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<meta-runner name="RunProcess">
<description>Run Process with Timeout</description>
<settings>
<parameters>
<param name="ExecutablePath" value="%teamcity.build.checkoutDir%" />
<param name="Parameters" value="" />
<param name="Timeout in s" value="" />
</parameters>
<build-runners>
<runner name="Run Process" type="jetbrains_powershell">
<parameters>
<param name="jetbrains_powershell_bitness" value="x86" />
<param name="jetbrains_powershell_execution" value="STDIN" />
<param name="jetbrains_powershell_noprofile" value="true" />
<param name="jetbrains_powershell_script_code"><![CDATA[$params = '%Parameters%'

Write-Host "---------------------------------------------------"
Write-Host "Start RunProcess meta-runner"
Write-Host "Executable: %ExecutablePath%"
Write-Host "Parameters: %Parameters%"
Write-Host "Timeout: %Timeout in s%"
Write-Host "---------------------------------------------------"

If([string]::IsNullOrEmpty($params)){
$p = Start-Process "%ExecutablePath%" -PassThru -NoNewWindow
}
Else{
$p = Start-Process "%ExecutablePath%" $params -PassThru -NoNewWindow
}

$timeouted = $null

# time for timeout is in seconds!
$p | Wait-Process -Timeout %Timeout in s% -ea 0 -ev timeouted

If($timeouted){
Write-Host "Killing the process after timeout!"
Write-Host "##teamcity[buildStatus status='FAILURE' text='Process did not terminate in specified timeout!']"
$p.Kill()
}

$returnCode = $p.GetType().GetField("exitCode", "NonPublic,Instance").GetValue($p)
If(($p.hasExited) -and ($returnCode -ne 0) -and (!$timeouted)){
Write-Host "##teamcity[buildStatus status='FAILURE' text='Process terminated with exit code != 0']"
}]]></param>
<param name="jetbrains_powershell_script_mode" value="CODE" />
<param name="teamcity.step.mode" value="default" />
<param name="jetbrains_powershell_edition" value="Desktop" />
</parameters>
</runner>
</build-runners>
</settings>
</meta-runner>

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

It hangs occasionally on agents with and without windows service. The logs are 

[14:35:31][Step 1/1] Executable wrapper: C:\Windows\System32\cmd.exe
[14:35:31][Step 1/1] Wrapper arguments: [/c, D:\TC\temp\buildTmp\powershell3434293120886528829.bat]
[14:35:31][Step 1/1] Command: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NonInteractive -ExecutionPolicy ByPass -Command - < D:\TC\temp\buildTmp\powershell793671990463622244.ps1
[08:44:01][Step 1/1] Process exited with code 1
[08:44:01][Step 1/1] Process exited with code 1 (Step: Run Process (PowerShell))
[08:44:01][Step 1/1] Step Run Process (PowerShell) failed
 
The TeamCity version is 2018.1.1 (build 58406). 
Can you please provide some hints or how to avoid such problems?
 
Thanks in advance, 
Best regards, 
Irin

 

0
1 comment

Hi Irin,

 

Please follow the steps here: https://confluence.jetbrains.com/display/TCD18/Common+Problems#CommonProblems-BuildworkslocallybutfailsormisbehavesinTeamCity

 

If it only happens during the meta runner, I'd recommend trying it as well on a build configuration (instead of meta runner) and seeing if there it works or fails as well.

0

Please sign in to leave a comment.