Jenkins: no tool named MSBuild found

前端 未结 5 1092
闹比i
闹比i 2021-02-02 02:25

Setting up a Pipeline build in Jenkins (Jenkins 2.6), copying the sample script for a git-based build gives: \"no tool named MSBuild found\". I have set MSBuild Tool in Ma

相关标签:
5条回答
  • 2021-02-02 02:37

    In Declarative Pipeline syntax, the tooling for MSBuild is a little clunkier. Here's how I've had to handle it, using a script block:

    pipeline {
      agent { 
        label 'win-slave-node'
      }
      stages {
        stage('Build') {
          steps {
            script {
              def msbuild = tool name: 'MSBuild', type: 'hudson.plugins.msbuild.MsBuildInstallation'
              bat "${msbuild} SimpleWindowsProject.sln"
            } 
          } 
        } 
      } 
    } 
    

    In the older Scripted Pipeline syntax, it could be like this:

    node('win-slave-node') {
      def msbuild = tool name: 'MSBuild', type: 'hudson.plugins.msbuild.MsBuildInstallation'
    
      stage('Checkout') {
        checkout scm
      }
    
      stage('Build') {
        bat "${msbuild} SimpleWindowsProject.sln"
      }
    }
    
    0 讨论(0)
  • 2021-02-02 02:43

    While the provided answer certainly works, you just have to provide the correct complete tool name.

    In our Installation, we had three different MSBuild versions available and I could just use the following

    ${tool 'MSBuild 15.0 [32bit]'}

    0 讨论(0)
  • 2021-02-02 02:45

    We have to define msbuild which is installed in Global Tool Configuration in script block

    stage('App_Build'){
                    steps{
                        tool name: 'MsBuild', type: 'msbuild'
                        bat "\"${tool 'MsBuild'}\"My.Service.sln /t:Rebuild /p:Configuration=Release"
    }
    }
    

    This will work

    0 讨论(0)
  • 2021-02-02 02:46

    For anyone having this problem and just trying to figure out what 'Tool' represents in Jenkins and where it is configured, see following screenshots:

    Go to Manage Jenkins -> Global Tool Configuration:


    Scroll down to MSBuild and click the button to expand the section:


    Here you can see what tool name to use to reference MSBuild (or add one):


    Then you can reference it for example like this: bat "\"${tool '15.0'}\" solution.sln /p:Configuration=Release /p:Platform=\"x86\" (example is not declarative syntax, but should show the idea)

    0 讨论(0)
  • 2021-02-02 02:56

    You have to define MSBuild in Jenkins => Manage Jenkins => Global Tool Configuration or use a different toolname which is already defined.

    ${tool 'toolname'}  returns the path defined for a tool in Global Tool Configuration.
    

    Warning: Pay attention to the path defined. Does it point to a folder or to msbuild.exe? You might have to append msbuild.exe:

     ${tool 'VS2017'}\msbuild.exe
    

    A simple snapshot for explaining the concept:

    0 讨论(0)
提交回复
热议问题