msbuild configuration on Jenkins cluster installed on windows - jenkins

I have jenkins installed on windows machine and trying to create pipeline for .net project.
The msbuild is not working on Jenkins pipeline and giving error msbuild not recognised internal or external command.
I tried passing as a script
Script{
def msbuild= tool name: 'ms',type:'MSBuild'
bat "\"${msbuild}\" ${workspace}//proj.sln /nologo /nr:false /p:Platform="Any CPU" /p: Configuration:Release /t:Clean"
}
As well in just pipeline formats
Step{
bat "ms ${workspace}//proj.sln /nologo /nr:false /p:Platform="Any CPU" /p: Configuration:Release /t:Clean"
}
In the pipeline but it is not able to find msbuild even though it is configured Global Tool and giving the same name in tool name,but not working.
However when tried as a freestyle project and tried building, i was able to list the msbuild configuration from drop-down to fetch 'ms'
Passed build file as ${workspace}//proj.sln
Command line parameters as
nologo /nr:false /p:Platform="Any CPU" /p: Configuration:Release /t:Clean
It was able to build correctly without any issues.
Not sure why it is not getting resolved in pipeline?
Any suggestions to fix this is helpful.
Tried giving the msbuild executable location from .Net application but it is a different system, it did not work.

Related

Unable to change MSBuild path in MSBuild Plugin

I have added my MSBuild v.16 to my path parameter on my windows machine.
If I run the NuGet restore for my project from my cmd, it works correctly.
If I run this command from my local jenkins, it picks the MSBuild v.14 under auto detect.
I tried giving the path to MSBuild in jenkins Global Configuration MSBuild but it does not resolve the problem.

How to use the Jenkins MSBuild plug-in in a Jenkinsfile?

I have Jenkins v2.60.3 with the MSBuild Plugin v1.27 installed on Windows.
I have configured the path to my msbuild.exe in Jenkins' Global Tool Configuration. I have also setup a Multi Branch Pipeline in Jenkins that picks up a Jenkinsfile from git repo successfully.
My question is: How do I invoke the MSBuild Plugin as a step in my Jenkinsfile?
Please note I know I can invoke msbuild.exe directly as a Windows batch step but I prefer to go through the MSBuild Plugin if possible.
`
It looks like MSBuild is not supported by pipeline yet
https://github.com/jenkinsci/pipeline-plugin/blob/master/COMPATIBILITY.md
You can try this in the meantime.
https://github.com/jenkinsci/pipeline-examples/blob/master/jenkinsfile-examples/msbuild/Jenkinsfile
Our teams need to migrate a ton of freestyle MSBuild jobs that were created in the UI. mjd's answer helped but still left me scratching my head. The examples just didn't work... until I figured out the disconnect.
Here's the secret sauce:
You have to call the "named msbuild configuration" directly using the
"bat" and "tool" commands.
go into the Config of one of your freestyle jobs that uses the MSBuild plugin
scroll down to the msbuild section and click the "MSBuild Version" drop down, take note of the exact names that are listed. This is your 'named msbuild configuration'. Choose one name that you will use in the next step.
open your jenkinsfile, locate the stage and step where you want to call msbuild, then add this line and replace 'MSBuild 15.0' with the name that you chose in step 2:
bat ""${tool 'MSBuild 15.0'}\\msbuild" SolutionName.sln /p:Configuration=Release /p:Platform="Any CPU" /p:ProductVersion=1.0.0.${env.BUILD_NUMBER}"
like so...
(For Declarative Pipelines, you'll need to put this inside of a "script" block. If you don't know what a 'Declarative Pipeline' is, it is one of two styles of writing pipeline scripts in Jenkins using the "groovy" language. For more info here is a comparison of the scripted vs declarative styles.)
run the pipeline and examine the output - the code you added in step three won't build anything, you just want to use it to see if msbuild will actually get called before investing anymore time into my script.
(I usually use the Replay button which allows me to edit the script online in Jenkins rather than editing, committing, and pushing to remote repo... it just saves a bit of time debugging.)
examine the output of the pipeline job you ran in step 4. You should see something like below indicating that the correct version of MSBuild was called. If not, you either have a typo or your administrator needs to intervene.
workspace\Pipeline_Test>"C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\MSBuild\15.0\Bin\msbuild" SolutionName.sln
/p:Configuration=Release /p:Platform="Any CPU"
/p:ProductVersion=1.0.0.308 Microsoft (R) Build Engine version
15.9.21+g9802d43bc3 for .NET Framework Copyright (C) Microsoft Corporation. All rights reserved.
Congratulations you can now configure your build! Replace SolutionName.sln with your build file and pass the correct parameters to it.
I am surprised that all solutions doesn't work for me.
Platform : Window 10 Jenkins at latest version in 2020-11-05.
I am not sure if there's any reason that window & other OS will cause the pipeline script engine behaved differently.
Below are the possible encountered issues and solution finally combined with the above solution.
in my compiler, a single '' will cause error, '' must be escaped by replaced by '\'. which is similar to other char such as '"'
${tool 'MSBuild'} OR ${tool 'MSBuild 15.0'}\msbuild\ does not work, the error is the path cannot specified or cannot find the bat program. It must be an absolute path of the actual msbuild.exe
So this is the working solution for adding MSbuild in the pipeline script in window platform's jenkin
bat '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild" YourSolution.sln /p:Configuration=Release /p:Platform="Any CPU" /p:ProductVersion=1.0.0.${env.BUILD_NUMBER}'

configuring jenkins msbuild path

I have configured a new msbuild path and name
in the jenkins configure tool. The configuration pointing to v15
I receive thew following error:
C:\jenkins_slave\cortana\workspace\xxx\testing>exit 0 FATAL:
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\MSBuild\15.0\Bin doesn't exist Build step
'Build a Visual Studio project or solution using MSBuild' marked build
as failure
How can I solve it?
In second screenshot you need to put slash at the end of the path:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\
However, to use Jenkins MSBuild plugin for VS2017 there are other things to consider. Launching MSBuild executable in my case required bunch of environment variables to be configured which otherwise are set in "Development Command Prompt".
I am contemplating using "dotnet build", "dotnet test" etc. in command line instead.

MSBuild configuration in jenkins

I am facing the error below during configuration of MSBuild in Jenkins:
[ImageResize] $ cmd.exe /C " msbuild.exe p:Configuration=Release
E:\Heena\Applications\ImageResize\vbimage\ImageResize.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 build as
failure Finished: FAILURE
Please note that I have set MSBuild path up to msBuild.exe during setting up of MSbuild plugin. I have successfully deployed Visual Studio project on jenkins, but unable to configure it with MSBuild.
In MSBuild installations option of jenkins,
Choose the path to MSBuild = C:\Windows\Microsoft.NET\Framework64\v4.0.30319
Then go to your respective jenkins project where you want to build,
from,Add Build Step menu choose
Build Visual Studio Project or solution using MSBuild option
MSBuild version will be what you defined in Step 1 and in MSBuild File
type the path of your solution file and in Command Line Arguments option
type /p:Configuration=Release.
Hope you got the answer what you were looking for.
A Guess from my side , msbuild.exe is not part of the PATH when you execute the msbuild command , check that before you run the command , try to export the the path to msbuild to the path variable.
Looking at the error i assume you are using windows/Batch , so try some thing like this before running msbuild
set PATH=%PATH%;path/to/msbuild/binary
Feel free to revert in case of any issues/concerns

Jenkins + NUnit with TFS on Build Server

I'm new to continuous integration. I'm trying to get Jenkins to execute unit tests from a TFS project. My Jenkins build (pre-NUnit build step) is successful and I've installed the NUnit Jenkins plugin and I've read this post, but it's failing with this error: "The system cannot find the path specified."
I think the trouble is that I'm NOT running from my local machine, so the test DLL that NUnit should be running is missing I think. How can I reference that DLL properly? Do I need an extra Build Step to copy the files or something? Here's my "Execute Windows Batch Command" build step command:
"C:\Program Files\NUnit 2.6.3\bin\nunit-console.exe Victoria.Tests.Integration/bin/Debug/Victoria.Tests.Integration.dll /xml=nunit-result.xml"
The problem is that your command is all in quotes, including the parameters.
Change
"C:\Program Files\NUnit 2.6.3\bin\nunit-console.exe Victoria.Tests.Integration/bin/Debug/Victoria.Tests.Integration.dll /xml=nunit-result.xml"
to
"C:\Program Files\NUnit 2.6.3\bin\nunit-console.exe" Victoria.Tests.Integration/bin/Debug/Victoria.Tests.Integration.dll /xml=nunit-result.xml

Resources