2013-10-10 167 views
0

我们试图在构建项目时使用Jenkins将一组“工作文档”转换为“发布文档”。这涉及服用的.docx文件并将其保存为.pdf文件,我们用下面的PowerShell脚本实现:Jenkins:将.docx转换为.pdf问题

$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() 

现在,该脚本工程100%,当我登录到詹金斯PC,我们所期望的方式并在Powershell中自己运行它。但是,当詹金斯试图运行它时,我们得到You cannot call a method on a null-valued expression$document.SaveAs$document.Close

我认为这是因为用户Jenkins运行时,SYSTEM没有访问.docx文件的权限,或者找不到Word安装,或者这种性质的东西,但我想不出如何我应该尝试进一步调试它。任何提示都非常感谢!

+0

创建一个空目录“桌面”你已经确定了两个可能的原因(在文件的权限,无法启动Word),所以通过更改地址开始**一个在时间**,看看它是否能解决问题。尝试以* *有权执行Word的用户身份运行Jenkins。如果这不起作用,请开始查看文件和文件夹的权限。 – alroc

+0

我会以相反的方式开始,因为我假设如果我没有启动Word的权限,null将来自$ word_app。 –

+0

这就是我的第一个建议。以拥有执行应用程序权限的用户身份运行Jenkins服务。 [系统无法运行桌面应用程序](http://stackoverflow.com/questions/5001065/how-can-i-run-a-application-under-system)。詹金斯可能不应该首先作为系统运行。 – alroc

回答

3

我有同样的问题,并找到一个简单的解决方法。

C:\Windows\SysWOW64\config\systemprofile\ 
+0

这对我有用。除非服务以当前登录的用户身份运行,否则更改运行的服务的运行方式不起作用,哪种方式会破坏作为服务运行的要点。 – Darryl