Teamcity powershell 运行器可在服务器上远程运行命令 [英] Teamcity powershell runner to remotely run commands on server

查看:67
本文介绍了Teamcity powershell 运行器可在服务器上远程运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,每当我尝试对我们的一个测试服务器进行远程调用时,TeamCity 就会挂起.

I have a strange issue where TeamCity just hangs whenever i try to do a remote call to one of our test servers.

目前的构建步骤是:

  • 的模板文件
  • 中编译代码
  • 打包项目
  • 将包发送到测试服务器
  • 在测试服务器上解压缩包
  • Template files for
  • Compile code in
  • Package project
  • Send package to test servers
  • Unzip package on test servers

现在一切正常,直到最后一个阶段,在远程服务器上解压缩包.现在我只想运行一个 powershell 命令来连接并运行命令然后退出.如果我从远程桌面使用 powershell,并且提供的用户凭据正确,则一切正常.

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.

正在运行的示例如下:

$password = ConvertTo-SecureString "%PasswordVar%" -AsPlainText -Force
$credentials = New-Object System.Manager.Automation.PsCredential("%UsernameVar%", $password)
etsn -computername %TestServer1Var% -Credential $credentials

当这被称为 TeamCity 刚刚挂起时,它必须手动停止,否则它将永远停留在代理上的这一步.我试过不使用凭据,我试过不使用 etsn 并使用完整的命令名称,还尝试了其他远程命令方法,但似乎没有任何效果.

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.

那么有没有办法让 TeamCity 实际运行命令?或者找出是什么导致它无限期地处理这一步?

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?

推荐答案

这是一个小问题的组合,对于 1,通过团队城市查询的用户没有正确解析域,因此需要将其添加到用户名 <代码>some-user@some-domain.还有一个问题是,在执行 PSSESSION 连接时会遇到某种连接限制,但是如果我使用脚本块切换到 Invoke-Command,它就可以正常工作.

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.

如果它对这里的任何人有帮助,那么我最终使用的命令是解压缩远程文件,使用 7zip 命令行作为本机解决方案似乎从未奏效.

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.

这篇关于Teamcity powershell 运行器可在服务器上远程运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆