2017-02-11 17 views
1

Jenkinsプラグインを使用してWord文書をテキストに変換しても、Null型のエラーが発生するPowerShellスクリプトを実行しようとしています。スレーブはWin 2008のボックスで、Jenkinsはサービスとして実行されており、サービスは管理者として実行されています。私は試しました:Jenkins PowerShell Plugin - Returning Null

  • リモートボックスでコマンドがローカルで実行されることを確認します。
  • Windowsバッチを使用してPowerShellスクリプトを実行する(同じエラー)。
  • Jenkinsプラグインを使用してコマンドを実行します。

スクリプト($DocがNullに設定されている):

私はWordオブジェクトを持ったファイルと、b)はa)の存在であることを確認した
$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 

答えて

1

以下を試してください。まず、Administratorに指定された場所でファイルを開く権利があるかどうかを確認します。エラー出力でスクリプトを拡張して、なぜ$Word.Documents.Open($File.FullName)$nullを返すかを確認します。

$Error.Clear() # Clear all other errors 
$Doc = $Word.Documents.Open($File.FullName) 
$Error.Count # Dump number of errors 
$Error # Dump errors 

なぜOpenが失敗するのかについての追加情報を取得することができます。

UPDATE:あなたは多分あなたのCOM/DCOMの設定を変更する必要があります - >このlinkの答えを確認してください。

+0

最初の質問をエラー出力で更新しました。 Jenkinsが使用するのと同じユーザ名/パスワードでリモートボックスにログインし、問題なくスクリプトを実行できます。 – stackbacker

+0

リンクありがとうございました。 99%が自信を持ってその方向を見たことはないと確信しています。それはDCOMの問題ではありませんが、それを修正したSysWowディレクトリ(そのリンクに記載)にDesktopを追加していました。再びありがとう。 – stackbacker

+0

ここにはうれしい。どういたしまして。 – Moerwald