Issue
I am trying to automatically build a software using Visual Studio's MSBuild tool. The issue is: Jenkins cannot find it.
My first attempt was to add the MSBuild.exe path to the environment variable PATH
. Great, that works. But then NuGet was missing, so I had to download nugget.exe and put its path to PATH
as well.
But now I am facing an issue I probably cannot solve easily. It cannot find CL.exe
. Even if I add it, there are other things missing.
So I did some research and found out about the vcvarsall.bat.
In my Jenkinsfile I tried something like this:
stages {
stage('Set up paths') {
steps {
bat '"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat x86"'
}
}
stage('Build') {
steps {
bat 'msbuild myProject.vcxproj /p:configuration=debug /p:platform=win32
}
}
}
But this does not work. MSBuild and CL.exe not found. I also tried to use call
and put them in one stage like this:
stage('Build') {
steps {
bat '''
call "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat x86"
call msbuild myProject.vcxproj /p:configuration=debug /p:platform=win32
'''
}
}
But it won't work either.
Now I am trying to get the vcvarsall run at boot time, but calling it does not effect new instances of cmd as it seems.
What can I do now? How can I set up those variables for a Jenkins build slave?
Solution
It seems that calling the vcvarsall in another step won't work at all. But calling them in the same bat statement as the msbuild it works. But: There are different vcvars files in different locations.
Since I only need 32 bit compilation (due to some old components...) I simply run the following Jenkinsfile with success:
pipeline {
agent any
stages {
stage('Build') {
steps {
bat '''
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars32.bat"
msbuild MsBuildTest.sln
'''
}
}
}
}
Answered By - user5444681