Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: no tool named MSBuild found

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 Manage Jenkins -> Global Tool Configuration. I am running pipeline on the slave node.

In Slave configuration, I have set MSBuild tool path in Node Properties -> Tool Locations.
While build process it is not able to get MSBuild tool path, if i run same source without pipeline (without using Jenkinsfile) it works fine.


Please see Jenkinsfile Syntax

pipeline {
    agent { label 'win-slave-node' }
    stages {
           stage('build') {
           steps {

           bat "\"${tool 'MSBuild'}\" SimpleWindowsProject.sln /t:Rebuild /p:Configuration=Release"
           }
    }
   }
}



I have also tried to change environment variable for windows slave it not refreshed.


NOTE: I have installed MS Build tool for on slave node

like image 609
Atul N Avatar asked Jul 31 '17 14:07

Atul N


2 Answers

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"
  }
}
like image 104
Nick Jones Avatar answered Nov 08 '22 17:11

Nick Jones


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:
Global Tool Configuration


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


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


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)

like image 8
jumbo Avatar answered Nov 08 '22 16:11

jumbo