24
votes

1. sharing violation

after following http://programmaticponderings.wordpress.com/2012/08/08/convert-vs-2010-database-project-to-ssdt-and-automate-publishing-with-jenkins-part-33/

    echo 'Copying Adventure Works Solution to Jenkins workspace...'
xcopy /s /E /H /Y /R "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3" "C:\Program Files (x86)\Jenkins\jobs\testing003\workspace" 

echo 'Deleting artifacts from previous builds...'
del "%WORKSPACE%\*_publish.zip" /F /Q

2.Build ms project with MS build

After add C:\Windows\Microsoft.NET\Framework\v4.0.30319\ environment variables path and set build C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe in Jenkins

'C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sqlproj' /p:Configuration=Database3 /p:Platform=AnyCPU /t:Build;Publish /p:SqlPublishProfilePath='C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.publish.xml' /p:UpdateDatabase=False


Executing the command cmd.exe /C msbuild.exe "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sqlproj" /p:Configuration=Database3 /p:Platform=AnyCPU /t:Build;Publish "/p:SqlPublishProfilePath=C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.publish.xml" /p:UpdateDatabase=False C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe && exit %%ERRORLEVEL%% from C:\Program Files (x86)\Jenkins\jobs\testing003\workspace
[workspace] $ cmd.exe /C msbuild.exe "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sqlproj" /p:Configuration=Database3 /p:Platform=AnyCPU /t:Build;Publish "/p:SqlPublishProfilePath=C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.publish.xml" /p:UpdateDatabase=False C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe && exit %%ERRORLEVEL%%
'msbuild.exe' is not recognized as an internal or external command,


C:\Users\User2>cmd.exe /C msbuild.exe "C:\Users\LAB-User2\Documents\Visual S
tudio 2012\Projects\Database3\Database3.sqlproj" /p:Configuration=Database3 /p:P
latform=AnyCPU /t:Build;Publish "/p:SqlPublishProfilePath=C:\Users\LAB-User2\Doc
uments\Visual Studio 2012\Projects\Database3\Database3.publish.xml" /p:UpdateDat
abase=False C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe && exit %%
ERRORLEVEL%% from C:\Program Files (x86)\Jenkins\jobs\testing003\workspace
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.18034]
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1008: Only one project can be specified.
Switch: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe

For switch syntax, type "MSBuild /help"

update Full Console output

Started by user anonymous
Building in workspace C:\Program Files (x86)\Jenkins\jobs\testing003\workspace
[workspace] $ cmd /c call C:\Windows\TEMP\hudson1045566609826009314.bat

C:\Program Files (x86)\Jenkins\jobs\testing003\workspace>echo 'Copying Adventure Works Solution to Jenkins workspace...' 
'Copying Adventure Works Solution to Jenkins workspace...'

C:\Program Files (x86)\Jenkins\jobs\testing003\workspace>xcopy /s /E /H /Y /R "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3" "C:\Program Files (x86)\Jenkins\jobs\testing003\workspace"  
C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sln
C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.v11.suo
C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\excludefiles.txt
C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3\Database3.dbmdl
Sharing violation

C:\Program Files (x86)\Jenkins\jobs\testing003\workspace>echo 'Deleting artifacts from previous builds...' 
'Deleting artifacts from previous builds...'

C:\Program Files (x86)\Jenkins\jobs\testing003\workspace>del "C:\Program Files (x86)\Jenkins\jobs\testing003\workspace\*_publish.zip" /F /Q 
Could Not Find C:\Program Files (x86)\Jenkins\jobs\testing003\workspace\*_publish.zip

C:\Program Files (x86)\Jenkins\jobs\testing003\workspace>exit 0 
Path To MSBuild.exe: msbuild.exe
Executing the command cmd.exe /C msbuild.exe "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sqlproj" /p:Configuration=Database3 /p:Platform=AnyCPU /t:Build;Publish "/p:SqlPublishProfilePath=C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.publish.xml" /p:UpdateDatabase=False C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe && exit %%ERRORLEVEL%% from C:\Program Files (x86)\Jenkins\jobs\testing003\workspace
[workspace] $ cmd.exe /C msbuild.exe "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sqlproj" /p:Configuration=Database3 /p:Platform=AnyCPU /t:Build;Publish "/p:SqlPublishProfilePath=C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.publish.xml" /p:UpdateDatabase=False C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe && 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

enter image description here

5

5 Answers

45
votes

If you want to build a .NET project using Jenkins, follow these steps:

  1. Install MsBuild Plugin

  2. Go to Jenkins -> Manage Jenkins -> Configure System (On newer versions: Jenkins -> Manage Jenkins -> Global Tool Configuration -> MSBuild) msbuild

  3. In the MSBuild section click the AddMsBuild button and specify the details:

    • Name: Name of the MsBuild
    • Path to MsBuild: Specify the path of msbuild.exe. Example: C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe
  4. Save and apply the changes.

  5. Select your job.

  6. Select Add Build Step.

  7. Select MsBuild version.

  8. Specify the path to the project file (.csproj or .sln)

msbuild in project

  1. Build your project.
7
votes

For the newer version of Jenkins, this option is available under this section ..

Manage Jenkins -> Global Tool Configuration ->  MSBuild

From this answer: https://stackoverflow.com/a/37939483/2880781

1
votes

For the latest version of jenkins (3.0), you have to configure MSBuild in in the Tools>Manage Jenkins menu. Name a job here eg: msbuild. Once that is done, go to the job. Under the MSBuild module select the build (in this case msbuild) and now kick off the job. You should be good to go.

0
votes

select the MSBuild Version in job's configuration,and the MSBuild Version is configured in your jenkins' configure system.

0
votes
  1. Install Visual Studio on the Server
  2. Log into your Jenkins
  3. Install the MSBuild Plugin
  4. Go to Jenkins > Manage Jenkins > Global Tool Configuration
  5. Click MSBuild Installations
  6. Click Add MSBuild
  7. Name: Visual Studio (i.e. Visual Studio 2019 Community)
  8. Path to MSBuild (i.e. C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin) enter image description here
  9. Click Save
  10. Go to your Jenkins Project
  11. Click Configure
  12. Go to Build
  13. Select your MSBuild Version
  14. Enter the name of your Solutin File enter image description here