2

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.

$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 srv2

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

0
3

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:

  1. Remove your Invoke-Command line and see if the program executes.
  2. Replace the ScriptBlock command with a simpler command, like Get-Culture, command and see if it still hangs.
  3. Replace your C:\hg\Update.ps1 with another script that performs a simple command.
  4. 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.

3
  • the only thing update.ps1 does is hg update, nothing else
    – Eddie
    Feb 8 '18 at 4:08
  • @Eman I have never used Mercurial, but it could be something to do with that command. Have you tried the debugging steps I provided?
    – Preston Martin
    Feb 8 '18 at 14:52
  • that was the problem.
    – Eddie
    Dec 15 '20 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.