Jenkins:找不到名为 MSBuild 的工具
Jenkins: no tool named MSBuild found
在 Jenkins (Jenkins 2.6) 中设置管道构建,为基于 git 的构建复制示例脚本给出:"no tool named MSBuild found"。我在 Manage Jenkins -> Global Tool Configuration
中设置了 MSBuild 工具。我在从属节点上 运行ning 管道。
在Slave配置中,我在Node Properties -> Tool Locations
中设置了MSBuild工具路径。
在构建过程中它无法获取 MSBuild 工具路径,如果我 运行 没有管道的相同源(不使用 Jenkinsfile)它工作正常。
请参阅 Jenkinsfile 语法
pipeline {
agent { label 'win-slave-node' }
stages {
stage('build') {
steps {
bat "\"${tool 'MSBuild'}\" SimpleWindowsProject.sln /t:Rebuild /p:Configuration=Release"
}
}
}
}
我也尝试过为 windows slave 更改环境变量,但它没有刷新。
注意:我已经在从属节点上安装了 MS 构建工具
在 Declarative Pipeline 语法中,MSBuild 的工具有点笨拙。这是我必须使用 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"
}
}
}
}
}
在旧的脚本管道语法中,它可能是这样的:
node('win-slave-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]'}
对于遇到此问题并试图弄清楚 'Tool' 在 Jenkins 中代表什么以及它的配置位置的任何人,请参见以下屏幕截图:
转到管理 Jenkins -> 全局工具配置:
向下滚动到 MSBuild 并单击按钮展开该部分:
这里可以看到用什么工具名来引用MSBuild(或者加一个):
然后你可以像这样引用它:bat "\"${tool '15.0'}\" solution.sln /p:Configuration=Release /p:Platform=\"x86\"
(示例不是声明性语法,但应该显示想法)
您必须在 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
解释概念的简单快照:
我们必须在脚本块中定义安装在全局工具配置中的 msbuild
阶段('App_Build'){
脚步{
工具名称:'MsBuild',类型:'msbuild'
bat ""${tool 'MsBuild'}"My.Service.sln /t:Rebuild /p:Configuration=Release"
}
}
这会起作用
在 Jenkins (Jenkins 2.6) 中设置管道构建,为基于 git 的构建复制示例脚本给出:"no tool named MSBuild found"。我在 Manage Jenkins -> Global Tool Configuration
中设置了 MSBuild 工具。我在从属节点上 运行ning 管道。
在Slave配置中,我在Node Properties -> Tool Locations
中设置了MSBuild工具路径。
在构建过程中它无法获取 MSBuild 工具路径,如果我 运行 没有管道的相同源(不使用 Jenkinsfile)它工作正常。
请参阅 Jenkinsfile 语法
pipeline {
agent { label 'win-slave-node' }
stages {
stage('build') {
steps {
bat "\"${tool 'MSBuild'}\" SimpleWindowsProject.sln /t:Rebuild /p:Configuration=Release"
}
}
}
}
我也尝试过为 windows slave 更改环境变量,但它没有刷新。
注意:我已经在从属节点上安装了 MS 构建工具
在 Declarative Pipeline 语法中,MSBuild 的工具有点笨拙。这是我必须使用 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"
}
}
}
}
}
在旧的脚本管道语法中,它可能是这样的:
node('win-slave-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]'}
对于遇到此问题并试图弄清楚 'Tool' 在 Jenkins 中代表什么以及它的配置位置的任何人,请参见以下屏幕截图:
转到管理 Jenkins -> 全局工具配置:
向下滚动到 MSBuild 并单击按钮展开该部分:
这里可以看到用什么工具名来引用MSBuild(或者加一个):
然后你可以像这样引用它:bat "\"${tool '15.0'}\" solution.sln /p:Configuration=Release /p:Platform=\"x86\"
(示例不是声明性语法,但应该显示想法)
您必须在 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
解释概念的简单快照:
我们必须在脚本块中定义安装在全局工具配置中的 msbuild
阶段('App_Build'){ 脚步{ 工具名称:'MsBuild',类型:'msbuild' bat ""${tool 'MsBuild'}"My.Service.sln /t:Rebuild /p:Configuration=Release" } }
这会起作用