Jenkins:未找到名为 MSBuild 的工具

问题描述 投票:0回答:5

在 Jenkins (Jenkins 2.6) 中设置管道构建,复制基于 git 的构建的示例脚本会给出:“未找到名为 MSBuild 的工具”。我已经在

Manage Jenkins -> Global Tool Configuration
中设置了MSBuild Tool。我正在代理节点上运行管道。

在代理配置中,我在
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 工具

jenkins msbuild jenkins-pipeline jenkins-agent
5个回答
15
投票

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

在旧的脚本化管道语法中,它可能是这样的:

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

  stage('Checkout') {
    checkout scm
  }

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

8
投票

对于遇到此问题并只是想弄清楚 Jenkins 中“工具”代表什么以及它的配置位置的任何人,请参阅以下屏幕截图:

转到管理 Jenkins -> 全局工具配置:


向下滚动到 MSBuild 并单击按钮展开该部分:


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


然后你可以像这样引用它:

bat "\"${tool '15.0'}\" solution.sln /p:Configuration=Release /p:Platform=\"x86\"
(示例不是声明性语法,但应该展示想法)


5
投票

您必须在 Jenkins => 管理 Jenkins => 全局工具配置中定义 MSBuild 或使用已定义的不同工具名称。

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

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

 ${tool 'VS2017'}\msbuild.exe

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


3
投票

虽然提供的答案确实有效,但您只需提供正确的完整工具名称即可。

在我们的安装中,我们提供了三个不同的 MSBuild 版本,我可以使用以下版本

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


0
投票

我们必须定义安装在脚本块的全局工具配置中的msbuild

阶段('App_Build'){ 脚步{ 工具名称:'MsBuild',类型:'msbuild' bat ""${tool 'MsBuild'}"My.Service.sln /t:Rebuild /p:Configuration=Release" } }

这会起作用

© www.soinside.com 2019 - 2024. All rights reserved.