I have a strange issue where TeamCity just hangs whenever i try to do a remote call to one of our test servers.
Currently the build steps are:
- Template files for
- Compile code in
- Package project
- Send package to test servers
- Unzip package on test servers
Now it all works fine up until the last stage, unzipping the package on the remote server. Now I wanted to just run a powershell command to connect up and run the commands then exit. This all works fine if I were using powershell from remote desktop, and the user credentials provided are correct.
An example of what is being run is below:
$password = ConvertTo-SecureString "%PasswordVar%" -AsPlainText -Force
$credentials = New-Object System.Manager.Automation.PsCredential("%UsernameVar%", $password)
etsn -computername %TestServer1Var% -Credential $credentials
When this is called TeamCity just hangs, it has to be manually stopped or it will stay on this step on the agent forever. I have tried not using credentials, I have tried not using etsn and using the full command name, also tried other remote command methods, nothing seems to work.
So is there a way to get TeamCity to actually run the commands? or find out what is causing it to process this step indefinately?
This was a mix of small issues, for 1 the user when queried via team city was not resolving the domain correctly so this needed to be added to the username some-user@some-domain
. There was also an issue in that the there was some sort of connection limit which was being hit when doing the PSSESSION connection, however if I changed over to Invoke-Command with a script block it worked fine.
If it helps anyone here is the command I ended up with to unzip a remote file, using 7zip command line as the native solution never seemed to work.
$password = ConvertTo-SecureString "%TestServer.Password%" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PsCredential("%TestServer.Username%",$password)
$scriptBlock1 = {`
`
$sevenZip = "%TestServer.ReleasePath%\7za.exe"; `
&$sevenZip x %TestServer.ReleasePath%\web-package.zip -o%TestServer.WebPath% * -aoa; `
}
Invoke-Command -computername %TestServer.Server% -Credential $credentials -scriptblock $scriptBlock1
One thing to remember is that the username contains the domain as listed above, also the magic quotes are needed to allow the script block to be spread over lines as well as the semi colon to indicate the tasks should be run together.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With