在 Jenkins (Jenkins 2.6) 中设置管道构建,复制基于 git 的构建的示例脚本会给出:“未找到名为 MSBuild 的工具”。我已经在
Manage Jenkins -> Global Tool Configuration
中设置了MSBuild Tool。我正在代理节点上运行管道。
Node Properties -> Tool Locations
中设置了MSBuild工具路径。
pipeline {
agent { label 'win-agent-node' }
stages {
stage('build') {
steps {
bat "\"${tool 'MSBuild'}\" SimpleWindowsProject.sln /t:Rebuild /p:Configuration=Release"
}
}
}
}
我也尝试过更改Windows代理的环境变量,但它没有刷新。
注意:我已经在代理节点上安装了 MS Build 工具
在 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"
}
}
虽然提供的答案确实有效,但您只需提供正确的完整工具名称即可。
在我们的安装中,我们提供了三个不同的 MSBuild 版本,我可以使用以下版本
${tool 'MSBuild 15.0 [32bit]'}
我们必须定义安装在脚本块的全局工具配置中的msbuild
阶段('App_Build'){ 脚步{ 工具名称:'MsBuild',类型:'msbuild' bat ""${tool 'MsBuild'}"My.Service.sln /t:Rebuild /p:Configuration=Release" } }
这会起作用