为什么我不能在TeamCity Agent上的PowerShell中解压缩?

时间:2012-02-16 20:43:21

标签: powershell zip teamcity

我有一个解压缩MVC包的脚本,缩小所有CSS和js文件,然后重新压缩它。它作为管理员或TeamCity帐户在我的机器和CI服务器上完美运行。当TeamCity将其拉下并运行时,脚本会提供所需的所有输出,不会报告错误,但它永远不会解压缩文件。

write-host "creating shell object"
$shell_app=new-object -com shell.application
write-host "creating zip file"
$zip_file = $shell_app.namespace("C:\temp\PokerLeagueWebSite.zip")
write-host "setting folder to unzip to"
$destination = $shell_app.namespace("C:\temp\zy98")
write-host "about to copy files from zip"
$destination.Copyhere($zip_file.items(), 0x4)
write-host "finished"

以下是TeamCity的输出:

[23:01:03]: Step 5/5: test ps1 file (Powershell)
[23:01:03]: [Step 5/5] Starting: C:\Windows\system32\cmd.exe /c
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -File
C:\TeamCity\buildAgent\work\71e78d4c543e0594\Tools\test.ps1 && exit /b %ERRORLEVEL%
[23:01:03]: [Step 5/5] in directory: C:\TeamCity\buildAgent\work\71e78d4c543e0594
[23:01:03]: [Step 5/5] creating shell object
[23:01:03]: [Step 5/5] creating zip file
[23:01:03]: [Step 5/5] setting folder to unzip to
[23:01:03]: [Step 5/5] about to copy files from zip
[23:01:03]: [Step 5/5] finished
[23:01:03]: [Step 5/5] Process exited with code 0
[23:01:03]: Publishing internal artifacts
[23:01:03]: [Publishing internal artifacts] Sending build.finish.properties.gz file
[23:01:03]: Build finished

如果我在TeamCity帐户的服务器上运行确切的命令,它可以正常工作:

C:\Windows\system32\cmd.exe /c C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -File C:\TeamCity\buildAgent\work\71e78d4c543e0594\Tools\test.ps1 && exit /b %ERRORLEVEL%

我只能认为这是TeamCity正在做的事情或与它作为服务运行的事实相关的东西,但我很难过,无法想出这个。

2 个答案:

答案 0 :(得分:3)

我使用了“user1545905”的答案,但我需要在服务器重启后手动重启TeamCity代理服务。 您可以在目录上为TeamCity代理服务用户提供完全控制。

答案 1 :(得分:1)

昨天我遇到了同样的问题。即使没有记录错误,它也与权限有关。我有一个用于构建代理的Windows Server计算机,并将其设置为作为Windows服务运行。我将服务的登录设置更改为用户而不是SYSTEM帐户,一切似乎都很好,直到我遇到同样的问题。在将代理作为服务运行时,我从未找到解决方法,因此我将其更改为从/bin/agent.bat文件运行代理。我可以通过将其作为计划任务运行并在启动时运行来实现相同的设置。但是,最终,改为不作为Windows服务运行为我解决了问题。