3

I have a script that unzips an MVC package, minifies all the CSS and js files, and rezips it. It works perfectly on my machine and on the CI server as an admin or the TeamCity account. When TeamCity pulls it down and runs it, the script gives all the output expected, doesn't report an error, but it will never unzip the file.

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"

Here is the output from 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

If I run the exact command on the server on the TeamCity account it works correctly:

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%

I can only think it is either something TeamCity is doing or something related to the fact it is running as a service, but I am stumped and can't figure this one out.

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
Jon
  • 15,110
  • 28
  • 92
  • 132

2 Answers2

3

I used the answer from "user1545905", but I needed to manually restart the TeamCity agent service after the server rebooted. You can give the TeamCity agent service user Full Control on the directory.

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
Bruce Liu
  • 384
  • 3
  • 6
  • Another option is to just use 7zip. Here is an example: [your7zipfolder]\7z.exe e -tzip "[yourzipfile]" -o[yourtargetfolder] -y – Bruce Liu Oct 09 '12 at 03:29
  • This answer isn't working for me. The user is already an admin and has FullControl on the folder. Do you think it matters that _my_ script is extracting to the redefined env.TEMP directory? (`c:\buildagent\temp\buildtmp`) – Anthony Mastrean Nov 06 '12 at 20:58
1

I ran into this same issue yesterday. It has something to do with permissions, even though no error was logged. I have a Windows Server machine for my build agent and had it setup to run as a Windows Service. I changed the Log In setting for the service to be a user instead of the SYSTEM account and everything seemed fine until I got the same problem you have. I never found a way to fix it when running the agent as a service so I changed it to run the agent from their /bin/agent.bat file. I could pretty much achieve the same setup by having it run as a scheduled task and run on startup. But, ultimately, changing to not run as a windows service fixed the problem for me.

Kevin Jett
  • 131
  • 6