Jenkinsプラグインを使用してWord文書をテキストに変換しても、Null型のエラーが発生するPowerShellスクリプトを実行しようとしています。スレーブはWin 2008のボックスで、Jenkinsはサービスとして実行されており、サービスは管理者として実行されています。私は試しました:Jenkins PowerShell Plugin - Returning Null
- リモートボックスでコマンドがローカルで実行されることを確認します。
- Windowsバッチを使用してPowerShellスクリプトを実行する(同じエラー)。
- Jenkinsプラグインを使用してコマンドを実行します。
スクリプト($Doc
がNullに設定されている):
$Files = Get-ChildItem 'PTX*.docx'
$Files
$Word = New-Object -ComObject Word.Application
$Word
foreach ($File in $Files) {
# open document in Word
$File.FullName
$Doc = $Word.Documents.Open($File.FullName)
$Doc
Start-Sleep -s 10
# swap out RTF for TXT in the filename
#$Name = ($Doc.FullName).Replace("docx", "txt")
#$Doc.SaveAs([ref] $Name, [ref] 2)
$Doc.Close()
}
。この場合も、これはリモートボックスでうまく動作します。
$Word
:$Doc
がセットやったことがなかったので
Application : Microsoft.Office.Interop.Word.ApplicationClass Creator : 1297307460 Parent : Microsoft.Office.Interop.Word.ApplicationClass Name : Microsoft Word Documents : System.__ComObject Windows : System.__ComObject ActiveDocument : . . .
エラーが近くで発生します。実行中に$Doc
を印刷しようとすると、何も表示されませんでした。
C:\jenkins\workspace\eggplant-Test\DVA.docx You cannot call a method on a null-valued expression. At C:\Users\PENDAN~1.MDZ\AppData\Local\Temp\hudson1097244472905940013.ps1:19 char:12 + $Doc.Close <<<<() + CategoryInfo : InvalidOperation: (close:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
更新:アンドレアス・Mによって提案された
変更されたスクリプトとして:
Foreach ($File in $Files) {
# open document in Word
echo File: $File.fullname
$Error.Clear() # Clear all other errors
$Doc = $Word.Documents.Open($File.FullName)
echo "Error count:" $Error.Count # Dump number of errors
$Error # Dump errors
echo "Doc:" $Doc
同じエラーが、奇妙なことに、Word.Doc.Openコールから報告エラーなし。
File:
C:\jenkins\workspace\eggplant-Test\DVA.docx
Error count:
0
Doc:
You cannot call a method on a null-valued expression.
At C:\Users\PENDAN~1.MDZ\AppData\Local\Temp\hudson3349169014447704754.ps1:23 ch
ar:12
+ $Doc.close <<<<()
+ CategoryInfo : InvalidOperation: (close:String) [], RuntimeExce
ption
+ FullyQualifiedErrorId : InvokeMethodOnNull
最初の質問をエラー出力で更新しました。 Jenkinsが使用するのと同じユーザ名/パスワードでリモートボックスにログインし、問題なくスクリプトを実行できます。 – stackbacker
リンクありがとうございました。 99%が自信を持ってその方向を見たことはないと確信しています。それはDCOMの問題ではありませんが、それを修正したSysWowディレクトリ(そのリンクに記載)にDesktopを追加していました。再びありがとう。 – stackbacker
ここにはうれしい。どういたしまして。 – Moerwald