1

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

1

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.

  • the only thing update.ps1 does is hg update, nothing else – Eman 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? – PrestonM Feb 8 '18 at 14:52
0

The problem was my script was hiding a prompt, when I ran the script on the server itself, there was a security prompt that I had to agree to, once I did that my script worked perfectly

to any future reader that close to losing their minds, run that script on the server and make sure its not asking something from you that the cli is going to hide from you

  • 1
    Isn't that what I suggested was the issue? That you were being prompted for something? – PrestonM Feb 8 '18 at 16:42
  • you did, I thank you for pointing me there – Eman Feb 8 '18 at 19:41

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.