我在安装了Windows 10专业版的计算机上设置了一个新的Jenkins主服务器。我在Windows Server 2012 R2上运行的旧Jenkins实例上复制构建作业。
构建调用一个bat文件,该文件在定义构建的.proj文件上调用msbuild.exe(与VS2015一起安装)。当我在命令行或visual studio中运行jenkins之外的构建时,它正确构建。当我在Jenkins中运行构建时,无论是使用MSBuild插件还是调用bat脚本,构建都会失败,这表明Jenkins环境中的配置错误(或缺失),但所有内容似乎都与旧的Jenkins实例配置相同
构建失败之一的堆栈跟踪:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: The "CL" task failed unexpectedly. [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: System.TypeInitializationException: The type initializer for 'Microsoft.Build.Utilities.FileTracker' threw an exception. ---> System.ArgumentException: The path is not of a legal form. [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: at System.IO.Path.GetPathRoot(String path) [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: at Microsoft.Build.Utilities.FileTracker..cctor() [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: --- End of inner exception stack trace --- [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: at Microsoft.Build.CPPTasks.CL.ComputeOutOfDateSources() [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: at Microsoft.Build.CPPTasks.TrackedVCToolTask.SkipTaskExecution() [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: at Microsoft.Build.Utilities.ToolTask.Execute() [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: at Microsoft.Build.CPPTasks.TrackedVCToolTask.Execute() [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Jenkins_workspace\Build_Job_Name\Project\Project.vcxproj]
解决方案文件中的每个.vcxproj项目都会出现此错误。
我在堆栈溢出和其他论坛上发现了几个MSB4018错误的情况,但更常见的是它不是一个不以文件名或不带引号的路径结束的路径带空格的\ filename。我甚至不确定这里引起问题的路径是什么。我在这里修改了vcxproj文件名的路径以删除特定信息,但我保留了路径的形式,只保留大小写字母和下划线。
有没有办法可以获得导致问题的路径,或者没有关于包含非法字符的路径的更具体信息?
编辑:当我使用Windows批处理命令构建步骤来调用msbuild或msbuild插件时,此问题在一个构建作业上是100%一致的,但在我使用的另一个构建作业上只是间歇性的一个groovy脚本来调用msbuild。
编辑2:我使用Jenkins 2.19遇到了这个问题。我发现如果我使用Jenkins 1.651这个问题消失了。事实证明这不是一个解决方案,问题是在旧版Jenkins上几天之后回来的,我又回到了新版本。
编辑3:我已经确定使用Visual C ++ Win32控制台应用程序DLL项目发生了这种失败。我使用Visual Studio 2015创建了一个helloworld.dll项目,并看到相同的构建失败:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: The "CL" task failed unexpectedly. [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: System.TypeInitializationException: The type initializer for 'Microsoft.Build.Utilities.FileTracker' threw an exception. ---> System.ArgumentException: The path is not of a legal form. [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: at System.IO.Path.GetPathRoot(String path) [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: at Microsoft.Build.Utilities.FileTracker..cctor() [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: --- End of inner exception stack trace --- [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: at Microsoft.Build.CPPTasks.CL.ComputeOutOfDateSources() [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: at Microsoft.Build.CPPTasks.TrackedVCToolTask.SkipTaskExecution() [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: at Microsoft.Build.Utilities.ToolTask.Execute() [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: at Microsoft.Build.CPPTasks.TrackedVCToolTask.Execute() [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Jenkins_workspace\mwe_test\helloworld\helloworld.vcxproj]
上面的所有路径都与构建计算机上的路径不同。我通过在VS2015 Visual C ++中选择新项目创建了mwe - &gt; Win32控制台应用程序并在向导中选择dll选项。然后我添加了以下helloworld.h头文件:
//helloworld.h
#pragma once
#ifdef HELLOWORLD_EXPORTS
#define HELLOWORLD_API __declspec(dllexport)
#else
#define HELLOWORLD_API __declspec(dllimport)
#endif
namespace helloworld
{
class Speak
{
public:
static HELLOWORLD_API void sayHello();
};
}
并将helloworld.cpp修改为:
// helloworld.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "helloworld.h"
#include <iostream>
namespace helloworld
{
void Speak::sayHello()
{
std::cout << "Hello World!\n" << std::endl;
}
}
这在视觉工作室中构建得很好,但在Jenkins下它失败了