0

プロジェクトをビルドするときに、Jenkins を使用して一連の「作業ドキュメント」を「リリース ドキュメント」に変換しようとしています。これには、.docx ファイルを取得して .pdf ファイルとして保存することが含まれます。これは、次の Powershell スクリプトを使用して実行します。

$documents_path = "E:\Documentation\Working Documents\"

$word_app = New-Object -ComObject Word.Application

echo $word_app

# This filter will find .doc as well as .docx documents
$files = Get-ChildItem -Path $documents_path -Filter *.doc? 

ForEach ($file in $files) {
    echo "Converting Document to PDF: $($file.FullName)"

    $document = $word_app.Documents.Open($file.FullName)
    $pdf_filename = "$($file.DirectoryName)\..\Release Documents\$($file.BaseName).pdf"
    $document.SaveAs([ref] $pdf_filename, [ref] 17)
    $document.Close()
}

$word_app.Quit()

これで、このスクリプトは、Jenkins PC にログインして Powershell で自分で実行すると、100% 期待どおりに機能します。しかし、Jenkins がそれを実行しようとするとYou cannot call a method on a null-valued expression$document.SaveAsandになり$document.Closeます。

これは、Jenkins を実行しているユーザーSYSTEMが .docx ファイルにアクセスする権限を持っていないか、Word のインストールなどを見つけることができないためだと思いますが、どのようにデバッグしようとすべきか考えられません。これより先です。どんなヒントでも大歓迎です!

4

1 に答える 1