TFS & GO & Chef, oh my: Part 9 - Lesson: Powershell & the GO Agent & ssh

Long story short, even if you have the GO Agent service (Windows) running as the correct user, commands will still pass as 'SYSTEM'.  Could not figure out how to change this, or get SYSTEM to use the id_rsa for the correct user (3+ hours of Google and trial/error).  So, here's an example command, old vs. new:

cmd /c powershell c:\scripts\BuildFileMove.ps1 %GO_PIPELINE_NAME%


cmd /c powershell $pass = convertto-securestring %GO_SHELL_PASS% -asplaintext -force;  $mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "%GO_SHELL_USER%",$pass; invoke-command -computername localhost -ScriptBlock {c:\scripts\BuildFileMove.ps1 %GO_PIPELINE_NAME%} -credential $mycred

The stuff that was failing, and how we figured it out:

  1. We're using Git for Windows (the command line, full bash integration), and trying to do push/pull
  2. The powershell scripts all run fine when done via the ISE/PS prompts, but when you try to get the GO Agent automating them, they would stop responding at the lines doing git/ssh work.
  3. After head bashing, we discovered this on the Git server: /var/log/secure
  4. SYSTEM was trying to log on via SSH and failing/hanging.
Using the "NEW" line above, it now works properly.  (if it hangs, not only do you need to restart the GO Agent service, but kill the ssh.exe process (which kills the sh.exe, sh.exe, and git.exe processes).

Honest.  To.  Goodness.

Amusingly, the Thoughtworks GO 'suggestion' when looking for command syntax is what I had to end up using...even though it's connecting to 'localhost'.  Kind of a roundabout way of ensuring the correct user key is used...but hey, it works.  All I had to set was a few pipeline variables (one secure variable) - GO_SHELL_USER, GO_SHELL_PASS.


Popular posts from this blog

DFSR - eventid 4312 - replication just won't work

Fixing duplicate SPNs (service principal name)

Logstash to Nagios - alerting based on Windows Event ID