简体   繁体   English

Msbuild通过VS和命令行运行,但通过Jenkins失败

[英]Msbuild works via VS and command-line, but fails via Jenkins

I am trying to build a VS .sln that has multiple C++ .vcproj's in it. 我试图建立一个具有多个C ++ .vcproj的VS .sln。 The solution file is generated using CMake and I've got this part working in Jenkins (with the CMake builder plugin). 解决方案文件是使用CMake生成的,并且我已经在Jenkins中使用CMake构建器插件来工作了。 To build the solution file, I am using msbuild. 要生成解决方案文件,我正在使用msbuild。 I am able to build the solution using both Visual Studio and from the command line with the following command: 我既可以使用Visual Studio,也可以使用以下命令从命令行构建解决方案:

C:\Jenkins\workspace\SonioTest>"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" /t:Rebuild bin/SonIO.sln

This builds successfully (on the same machine that Jenkins resides). 这样可以成功构建(在Jenkins所在的同一台计算机上)。

However, I am trying to automate this portion of the build in Jenkins and the build ends up failing with a couple of C1083 errors ( "Cannot open source file: '..\\path\\to\\file.ext': No such file or directory ). I have tried using both the Jenkins msbuild plugin and using the exact same command that works in the terminal as a "Execute Windows batch command" build step, with the same result. 但是,我正在尝试在Jenkins中自动化构建的这一部分,并且构建最终因几个C1083错误而失败( "Cannot open source file: '..\\path\\to\\file.ext': No such file or directory )。我尝试使用Jenkins msbuild插件,并使用在终端中作为“执行Windows批处理命令”构建步骤使用的完全相同的命令,结果相同。

When using the Windows batch command build step, I can see in the log that the command being executed: 当使用Windows批处理命令构建步骤时,我可以在日志中看到正在执行的命令:

C:\Jenkins\workspace\SonioTest>"C:\Windows\Microsoft.NET\Framework\v4.0.30319 msbuild.exe" /t:Rebuild bin/SonIO.sln

... is exactly the same as the one that works from the command line, including the working directory. ...与从命令行工作的目录( 包括工作目录)完全相同。

I am running Jenkins as a service and I have the service logon as my account (with administrator privileges). 我正在将Jenkins作为服务运行,并且将服务登录作为我的帐户(具有管理员权限)。 Anyone know what directory Jenkins will execute batch commands out of? 有人知道詹金斯将从哪个目录执行批处理命令吗?

Any ideas why I'm seeing this difference of behavior between Jenkins and the command line? 有什么想法为什么我会看到Jenkins和命令行之间的这种行为差异?

This is as much a workaround as a solution, but I ended up using devenv instead of msbuild and it works fine. 这是一种解决方案,但是我最终使用了devenv而不是msbuild ,它工作正常。

I know that this hints strongly as it being an environmental issue, but since it's not a problem to have VS installed on the build server, I decided to save the time that would be spent in the msbuild rabbit hole. 我知道这很明显地暗示了这是一个环境问题,但是由于在构建服务器上安装VS并不是问题,所以我决定节省在msbuild兔子洞中所花费的时间。

Without knowing much about VS build, it looks mostly like an environment setup. 在不了解VS构建的情况下,它看起来大多像是环境设置。

My first advice would be to make sure, in Jenkins, you change directory to the same directory you ran the good command from and try it then. 我的第一个建议是确保在Jenkins中,将目录更改为从中运行好命令的目录,然后再尝试。

Also, might want to try running Jenkins as a standalone app first. 另外,可能想先尝试将Jenkins作为独立应用程序运行。

And as a service, maybe allow service to "interact with desktop". 作为一项服务,也许允许服务“与桌面交互”。

The environment being used by the account that the Jenkins slave agent is not the same environment as you use when doing the same command line from a prompt. Jenkins从属代理程序所使用的环境与您在提示符下执行相同的命令行时所使用的环境不同。 Compare the two environments, note the difference, then add them to the Jenkins job. 比较这两种环境,注意差异,然后将它们添加到Jenkins作业中。

To get the environment of the slave while running, have it do a "set" from a Windows Command Prompt 要在运行时获取从站的环境,请通过Windows命令提示符对其进行“设置”

I may be late to the party, but I still ran into this problem on a new Jenkins setup on Server 2016. 我可能参加聚会的时间很晚,但是我仍然在Server 2016的新Jenkins安装程序上遇到此问题。

My solution was to use the MSBUILD straight from the VS2017 installation C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin . 我的解决方案是直接从VS2017安装C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin使用MSBUILD。 No more errors. 没有更多的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM