为什么我不能在TeamCity代理上使用PowerShell解压缩?

3

我有一个脚本,它可以解压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正在做某些事情,或者与其作为服务运行有关,但我被难住了,无法解决这个问题。


因为我仍然有这个问题,所以我在Jetbrains的YouTrack上开了一个问题。 - Anthony Mastrean
2个回答

3

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


另一个选择是只使用7zip。以下是一个示例:[your7zipfolder]\7z.exe e -tzip "[yourzipfile]" -o[yourtargetfolder] -y - Bruce Liu
这个答案对我没用。用户已经是管理员并且对文件夹拥有完全控制权限。你认为问题出在我的脚本提取到重新定义的 env.TEMP 目录上吗?(c:\buildagent\temp\buildtmp - Anthony Mastrean

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接