Jenkins: no tool named msbuild was found

Setting up pipeline assembly in Jenkins (Jenkins 2.6), copying a sample script for assembly with git gives: "no tool named MSBuild was found." I installed the MSBuild tool in Manage Jenkins -> Global Tool Configuration. I run the pipeline on the node slave.

In the Slave configuration, I set the path to MSBuild's tool Node Properties -> Tool Locations.
During the build process, it cannot get the path to the MSBuild tool, if I run the same source without a pipeline (without using Jenkinsfile), it works fine.


See Jenkinsfile File Syntax

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

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



slave Windows, .


. MS Build node

+7
5

Declarative Pipeline MSBuild clunkier. , script:

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"
        } 
      } 
    } 
  } 
} 

Scripted Pipeline :

node('win-slave-node') {
  def msbuild = tool name: 'MSBuild', type: 'hudson.plugins.msbuild.MsBuildInstallation'

  stage('Checkout') {
    checkout scm
  }

  stage('Build') {
    bat "${msbuild} SimpleWindowsProject.sln"
  }
}
+12

, , "" Jenkins , . :

Jenkins → :
Global Tool Configuration


MSBuild , :
MSBuild tool installations


, MSBuild ( ):
MSBuild tool name


, , : bat "\"${tool '15.0'}\" solution.sln /p:Configuration=Release /p:Platform=\"x86\" ( , )

+7

, , , .

MSBuild,

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

+2

MSBuild Jenkins => Manage Jenkins => Global Tool Configuration , .

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

Note: pay attention to the given path. Does this point to a folder or to msbuild.exe? You may need to add msbuild.exe:

 ${tool 'VS2017'}\msbuild.exe

A simple snapshot to explain the concept: How to use Jenkins tool paths in scripts

+2
source

We must define msbuildwhich is set in the Global Tool Configuration in the script block

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

It will work

0
source

Source: https://habr.com/ru/post/1682671/


All Articles