TeamCity Powershell ランナーが .ps1 ファイルを実行すると、Powershell コミュニティ拡張の一部である Write-Zip コマンドが認識されません。
ビルド サーバーで同じコマンドを手動で実行すると、問題なく動作します。TeamCity と私の両方が x64 バージョンの powershell.exe を実行しており、両方が同じユーザーとして実行されていることを確認しました。
[17:21:22][Step 5/5] Packaging WWW.zip
[17:21:45][Step 5/5] Write-Zip : The term 'Write-Zip' is not recognized as the name of a cmdlet,
[17:21:45][Step 5/5] function, script file, or operable program. Check the spelling of the name, or
[17:21:45][Step 5/5] if a path was included, verify that the path is correct and try again.
[17:21:45][Step 5/5] At
[17:21:45][Step 5/5] C:\TeamCity\buildAgent\work\e19b1309c030c7e2\Build\PowerShell\Package.ps1:20
[17:21:45][Step 5/5] char:1
[17:21:45][Step 5/5] + Write-Zip -InputObject $items -OutputPath .\WWW.zip
[17:21:45][Step 5/5] + ~~~~~~~~~
[17:21:45][Step 5/5] + CategoryInfo : ObjectNotFound: (Write-Zip:String) [], CommandNo
[17:21:45][Step 5/5] tFoundException
[17:21:45][Step 5/5] + FullyQualifiedErrorId : CommandNotFoundException
[17:21:45][Step 5/5]
別の環境から実行されているpowershellに関連している可能性があると思いますが、まだ完全には理解していません。
TeamCity ビルド ログで、スクリプトが次のように実行されていることがわかりました。
C:\Windows\sysnative\cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -File C:\TeamCity\buildAgent\work\e19b1309c030c7e2\Build\PowerShell\Package.ps1 -WorkingDirectory C:\TeamCity\buildAgent\work\e19b1309c030c7e
powershell が C:\Windows\sysnative\cmd.exe によって実行されていることに注意してください。
ただし、ビルド サーバーでは、このディレクトリまたは cmd.exe のバージョンが表示されず、PowerShell またはコマンド プロンプトから同じコマンドを実行しようとすると、C:\Windows\sysnative が見つからないと表示されます。 \cmd.exe
TeamCity が実際に Powershell を実行する方法を知っている人はいますか?
アップデート
Command Line Runner を使用して powershell スクリプトを実行し、TeamCity と同じように -File コマンドを使用して powershell.exe を呼び出してみました。
TaskManager を実行していて、それが実行した cmd.exe プロセスが C:\Windows\SysWOW64\cmd.exe であることを確認しました
上記とまったく同じエラーが発生しました。Write-Zip が認識されません。ただし、...\SysWOW64\cmd.exe で同じコマンドを手動で実行すると、機能します。
繰り返しになりますが、TaskManager によると、両方が同じマシンで同じユーザーとして実行されています。