无法在Hudson中使用Maven和C++项目成功构建

3

我在Hudson上有一个项目,使用maven构建。它编译C++源代码以创建可在项目的其他部分中使用的可执行文件。它使用Visual Studio工具,特别是一个导致麻烦的工具。当它尝试加载midl程序时,找不到它。如果我登录到存放Hudson的服务器并尝试在该特定项目中运行mvn clean install,则会收到以下错误消息:

D:\Hudson\jobs\{project-name}>mvn clean install
.
.
.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.876s
[INFO] Finished at: Mon Jan 14 21:56:18 PST 2013
[INFO] Final Memory: 8M/154M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (build-tlb) on project interop: Command execution failed.
Cannot run program "midl" (in directory "D:\Hudson\jobs\{project-name}"): CreateProcess error=2, The system cannot find the file specified ->     [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR]     [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

解决这个问题的方式是加载Visual Studio工具:
D:\Hudson\jobs\{project-name}>%VS100COMNTOOLS%\vsvars32.bat
Setting environment for using Microsoft Visual Studio 2010 x86 tools.

完成此操作后,我成功生成了一份干净的构建版本:
D:\Hudson\jobs\{project-name}>mvn clean install
.
.
.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.331s
[INFO] Finished at: Mon Jan 14 21:59:06 PST 2013
[INFO] Final Memory: 13M/222M
[INFO] ------------------------------------------------------------------------

但是,当Hudson自动启动构建时,这种方法就不再适用了。我尝试通过执行以下步骤来加载那个bat文件(vsvars32.bat):

pushd %VS100COMNTOOLS%
vsvars32.bat
popd

在开始maven进程之前,我知道这个工作是有效的,因为我在控制台输出中看到了这个信息:
C:\Apps\MicrosoftVisualStudio-10.0\Common7\Tools>vsvars32.bat
Setting environment for using Microsoft Visual Studio 2010 x86 tools.

但是每当到达实际使用MIDL的时候,我在BUILD FAILURE之后得到以下输出:

[INFO] o.h.m.e.h.MavenExecutionResultHandler - Build failed with exception(s)
[INFO] o.h.m.e.h.MavenExecutionResultHandler -     [1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (build-tlb) on project interop: Command execution failed.
[DEBUG] Closing connection to remote

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (build-tlb) on project interop: Command execution failed. Cannot run program "midl" (in directory "D:\Hudson\jobs\{project-name}"): CreateProcess error=2, The system cannot find the file specified ->     [Help 1]

我还在Hudson配置面板中设置了环境变量对 {VS100COMNTOOLS,C:\Apps\MicrosoftVisualStudio-10.0\Common7\Tools}。我不知道还需要做什么,请帮忙检查一下。

我不是Hudson专家,但请考虑运行Hudson的操作系统用户,也许您之所以能够使用不同的操作系统用户来运行它而使其工作?另外,请检查.bat文件的内容,当您执行“pushd和popd”时,它是否可能在单独的shell实例上设置了一些东西,而不是在当前shell上? - gerrytan
@gerrytan 谢谢,单独的实例 shell 是个好提示,我终于搞明白了。 - amaurs
1个回答

4
我最终解决了这个问题。Hudson调用新任务的方式是调用一个新的cmd窗口,因此%VS100COMNTOOLS%\vsvars32.bat工具会在不同实例中设置。查看%MAVEN_HOME%\bin中的mvn.bat,它允许您在之前调用批处理文件: 如果存在“%HOME%\mavenrc_pre.bat”则调用“%HOME%\mavenrc_pre.bat” 我在那里调用了%VS100COMNTOOLS%\vsvars32.bat,因此每次运行maven时都会加载可视化工具。然而,似乎Hudson没有通过调用该特定的bat文件来启动maven任务,它以某种方式创建了自己的maven实例,忽略了mavenrc_pre.bat。解决此问题的方法是将任务创建为批处理任务而不是Maven任务,然后简单地调用: mvn clean install 这解决了我的问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接