37

I have a .net application built on .net framework 3.5, I am trying to build this application on Jenkins CI server. I've added MSBuild plugin and and have added path to the .exe file of 2.0, 3.5 and 4.0 versions of MSBuild. But my building processes are failing by showing the below error message.

Path To MSBuild.exe: msbuild.exe  
Executing command: cmd.exe /C msbuild.exe Neo.sln && exit %%ERRORLEVEL%%  
[Test project] $ cmd.exe /C msbuild.exe Neo.sln && exit %%ERRORLEVEL%%  
'msbuild.exe' is not recognized as an internal or external command,  
operable program or batch file.  
Build step 'Build a Visual Studio project or solution using MSBuild.' marked uild as failure  
Finished: FAILURE  

Could anyone plz help me out..??

Shrayas
  • 6,784
  • 11
  • 37
  • 54
Bijoy K Jose
  • 1,342
  • 3
  • 15
  • 26

5 Answers5

84

To make the MSBuild plugin work, you need to configure the plugin in the Jenkins management screen.

NOTE: in the newer Jenkins versions you find the MSBuild configuration in the Global Tool Configuration:

enter image description here


Jenkins MSBuild Installation Configuration

Note the "Name" field, where I've called this particular configuration v4.0.30319. You could call it anything you like, but ideally the name will somehow refer to the version.

You'll need to refer to this name later in the Jenkins PROJECT that's failing.

Note: The yellow warning implies that the Path to MSBuild field should be populated with a directory name rather than a file name. In practice you do need to enter the filename here too (ie. msbuild.exe) or the build step will fail.

In the Jenkins project that's failing, go to the MSBuild build step.

The first field in the build step is "MSBuild Version". If you created the build step before configuring any MSBuild versions, the value here will be (default).

Jenkins MSBuild build-step, with (default) msbuild configuration selected

After configuring one or more MSBuild versions, the drop down will be populated with the available configurations. Select the one you require.

You can see here that I've now selected the named configuration that matches the installation above.

Jenkins MSBuild build-step, with named msbuild configuration selected

Liam
  • 27,717
  • 28
  • 128
  • 190
Damith
  • 62,401
  • 13
  • 102
  • 153
  • 1
    I looked at the yellow warning and removed the `msbuild.exe` and kept getting the error.. your answer was the only one which mentioned anything about that, and so glad you added that! – iamserious Jan 05 '15 at 16:02
  • Could I build that two projects just use one **Build a Visual Studio project or solution using MSBuild** section? – MichaelMao Dec 17 '15 at 02:38
  • If you're using VS2015/C# 6 with msbuild, you should specify the msbuild file path to ***C:\Program Files (x86)\MSBuild\14.0\Bin***, thanks for jessehouwing's solution: http://stackoverflow.com/a/32008030/1677041 – Itachi Jul 07 '16 at 06:55
  • I am not having MSBuild\14.0\ folder in my program files. I have installed VS2015 Profession. Where can I get this MSBuild Tool 2015 also did not help. – hirenhcm Aug 02 '16 at 14:23
  • Why do we need to give a .sol/.proj? Shouldnt Jenkins build the project in the Workspace folder? – Lakshay Dulani May 29 '17 at 12:37
  • MSBuild can be downloaded form here https://www.visualstudio.com/downloads/ – Liam Dec 06 '17 at 14:44
13
Jenkins | Manage Jenkins | Configure System

scroll down to the MSBuild section and click MSBuild installations

define the full path to msbuild.exe, on my system I have 3.5 and v4.0.30319

Note - specify the path to 32-bit tools even on a 64-bit system, otherwise you might get an error message:

Building Windows Phone application using MSBuild 64 bit is not supported.

So in Jenkins - it could be for example:

Name: Version 3.5

Path: C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe

Name: Version 4.0

Path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe

mbinette
  • 5,094
  • 3
  • 24
  • 32
Pavel Zeman
  • 131
  • 1
  • 5
6

I think you should set an absolute path for "msbuild.exe" in your Jenkins configuration, for example:

C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe
fmgp
  • 1,638
  • 17
  • 17
  • 1
    He's right. There is a bug in the plug-in. The Jenkins Configuration asks for the path to the MSBuild.exe, but actually has to be the FULL path of the MSBuild.exe. It will warn you, but you can save it this way and it works. – justdan23 Jul 09 '15 at 21:34
2

You can also add the path where the msbuild.exe is, to the PATH system environment variable of the node (or nodes) that is running that specific job.

-2

You could try executing the

%comspec% /k ""c:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86

command, which will temporarily update your environment path variables to reflect the VS2010 build environment. Execute this before you call MSBUILD and see what happens. I use this in my own build scripts with no issues.

Side note; it's very likely counterproductive to have multiple versions of MSBUILD on your PATH. Concentrate on getting one version working and go from there.

Mel Padden
  • 983
  • 1
  • 9
  • 21
  • 2
    I recommend using the MSBuild Plug-In for Jenkins. However, if you do want to build a command line script, don't use %comspec%, instead use 'CALL' without any extra parameters and the environment will remain for the rest of your script. For example: CALL "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 – justdan23 Jul 09 '15 at 21:36