patternshellMinor
Powershell script in jenkins is hanging
Viewed 0 times
scriptpowershelljenkinshanging
Problem
I'm building a process to automate deploys using Jenkins and I have an issue getting the code on the server
I have a powershell script on the deploy server that all it does is do an hg update command.
the script always hangs at the 'web1-dev output:' portion.
I'm kinda new to powershell scripting so its possible I'm doing something wrong, and if there's a better way to call a remote powershell script, I'm open to that
I have a powershell script on the deploy server that all it does is do an hg update command.
$ciPwd = ConvertTo-SecureString $env:CI_SERVER_PWD -AsPlainText -Force
$ciCredential = New-Object System.Management.Automation.PSCredential ($env:CI_SERVER_USR, $ciPwd)
Invoke-Command -ComputerName web1-dev,web2-dev -Credential $ciCredential -ScriptBlock { C:\hg\Update.ps1 } -InDisconnectedSession -SessionName srv1,srv2
Write-Host "web1-dev output:"
Receive-PSSession -Name srv1
Remove-PSSession -Name srv1
Write-Host "web2-dev output:"
Receive-PSSession -Name srv2
Remove-PSSession -Name srv2the script always hangs at the 'web1-dev output:' portion.
I'm kinda new to powershell scripting so its possible I'm doing something wrong, and if there's a better way to call a remote powershell script, I'm open to that
Solution
I'm guessing that your PowerShell script is hanging because of the Invoke-Command command. My best guess is PowerShell is either prompting you for something, you are passing in an argument incorrectly, or you are executing the script in your script block incorrectly. I'm not sure exactly how Script-Block works when referencing paths to PowerShell scripts, but it could be because C:\hg\Update.ps1 does not exist on the remote server. It could also be because of the commands in your "C:\hg\Update.ps1" script. Some debugging tips that I recommend:
And of course as with all PowerShell remoting issues, you should check that your firewall and network settings on the remote server allow connections from Jenkins over ports 5985 and 5986.
- Remove your Invoke-Command line and see if the program executes.
- Replace the ScriptBlock command with a simpler command, like Get-Culture, command and see if it still hangs.
- Replace your C:\hg\Update.ps1 with another script that performs a simple command.
- If all of those options still hang, try using the simple script method, but with different args.
And of course as with all PowerShell remoting issues, you should check that your firewall and network settings on the remote server allow connections from Jenkins over ports 5985 and 5986.
Context
StackExchange DevOps Q#3302, answer score: 3
Revisions (0)
No revisions yet.