Sunday, April 26, 2015

Jenkins: Fix errors in using MSBuild and MSTests plugin for building and test running C# project in Jenkins

Today I was trying to test run the CI of a C# project in Jenkins. To do this, i have installed the msbuild and mstest related plugins in Jenkins (MSBuild Plugin, MSTest Plugin, MSTestRunner Plugin) and restarted jenkins. However, after I added in a build step using option ''Build a Visual Studio project or solution using MSBuild'. I encountered build failure in which the console output from the build states that

'msbuild.exe' is not recognized as an internal or external command

The problem turns out that i did not have the msbuild in my Windows environment path. After I added in the "C:\Windows\Microsoft.NET\Framework\v4.0.30319" (which contains the command msbuild.exe) to my path, the build is successful.

Furthermore, also need to add the "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE" (which contains mstest.exe) to the path, otherwise the MSTest plugin will throw error

Note that the above process sometimes may make mstests throw some errors such as the following:

ERROR: Build step failed with exception
 at org.jenkinsci.plugins.MsTestBuilder.perform(
 at hudson.tasks.BuildStepMonitor$1.perform(
 at hudson.model.AbstractBuild$AbstractBuildExecution.perform(
 at hudson.model.Build$
 at hudson.model.Build$BuildExecution.doRun(
 at hudson.model.AbstractBuild$
 at hudson.model.Run.execute(
 at hudson.model.ResourceController.execute(
Build step 'Run unit tests with MSTest' marked build as failure
Finished: FAILURE

The better way can be done via jenkins, go to jenkins and click "Manage Jenkins" and then click "Configure Systems", Add a "MSBuild" and "MSTest" version there, and then add the paths of MSBuild and MSTest in your system to the "MSBuild" and "MSTests" section there (these are added by the MSBuild and MSTest plugins), As shown in the following screenshots

Then go back to your project and set the MSBuild version and MSTest version to the ones created in the "Configure Systems", as shown in the figure below:

After this step, you can remove MSBuild and MSTest from your system environment path variable, and restart your jenkins, and it will work.

No comments:

Post a Comment