Jenkins:未找到名为MSBuild的工具

yk9xbfzb  于 11个月前  发布在  Jenkins
关注(0)|答案(5)|浏览(169)

在Jenkins(Jenkins 2.6)中设置一个Pipeline构建,复制基于git的构建的示例脚本给出:“未找到名为MSBuild的工具”。我已经在Manage Jenkins -> Global Tool Configuration中设置了MSBuild Tool。我正在代理节点上运行pipeline。
在代理配置中,我在Node Properties -> Tool Locations中设置了MSBuild工具路径。
在构建过程中,它无法获得MSBuild工具路径,如果我运行相同的源代码而不使用管道(不使用Jenkinsfile),它工作得很好。
请参阅Jenkinsfile

pipeline {
    agent { label 'win-agent-node' }
    stages {
           stage('build') {
           steps {
    
           bat "\"${tool 'MSBuild'}\" SimpleWindowsProject.sln /t:Rebuild /p:Configuration=Release"
           }
    }
   }
}

字符串
我也试过改变环境变量为windows代理它不刷新。

注意:我已经在代理节点上安装了MS Build工具

inn6fuwd

inn6fuwd1#

在Declarative Pipeline语法中,MSBuild的工具有点笨拙。下面是我如何处理它的,使用script块:

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

字符串
在旧的Scripted Pipeline语法中,它可能是这样的:

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

  stage('Checkout') {
    checkout scm
  }

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

ryhaxcpt

ryhaxcpt2#

对于任何有这个问题的人,只是想弄清楚'工具'在Jenkins中代表什么以及它在哪里配置,请参阅以下屏幕截图:
点击Manage Jenkins -> Global Tool Configuration:
x1c 0d1x的数据
向下滚动到MSBuild并单击按钮以展开该部分:


的数据

在这里您可以看到使用什么工具名称来引用MSBuild(或添加一个):



然后你可以像这样引用它:bat "\"${tool '15.0'}\" solution.sln /p:Configuration=Release /p:Platform=\"x86\"(示例不是声明性语法,但应该显示想法)

ibps3vxo

ibps3vxo3#

您必须在Jenkins => Manage Jenkins => Global Tool Configuration中定义MSBuild,或者使用已经定义的其他工具名。

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

字符串
警告:请注意定义的路径。它是指向文件夹还是指向msbuild.exe?您可能必须附加msbuild.exe:

${tool 'VS2017'}\msbuild.exe


一个简单的快照来解释这个概念:

goqiplq2

goqiplq24#

虽然提供的答案肯定有效,但您只需提供正确的完整工具名称。
在我们的安装中,我们有三个不同的MSBuild版本可用,我可以只使用以下版本
第一个月

fbcarpbf

fbcarpbf5#

我们必须在脚本块中定义安装在全局工具配置中的msbuild
stage('App_Build'){ steps{ tool name:'MsBuild',type:'msbuild' bat“"${tool 'MsBuild'}“My. Service. sln/t:Rebuild /p:Configuration=Release”} }
这将工作

相关问题