首页 > 解决方案 > MsBuild 在 Jenkins 上失败

问题描述

我在 Jenkins 中创建了一个这样的管道:

pipeline {
    agent any
    stages {
        stage('Clean') {
            steps {
                cleanWs()
            }
        }
        stage('Checkout code') {
            steps {
                git branch: 'test', credentialsId: <credentialsId>, url: <githubUrl>
            }
        }
        stage('Restore Nuget') {
            steps {
                bat '"C:\\Nuget\\nuget.exe" restore <ProjectName>.sln'
            }
        }
        stage('Build') {
            steps {
                bat "\"${tool 'MSBuild'}\" <ProjectName>.sln /p:Configuration=Release;Platform=\"Any CPU\""
            }
        }
    }
}

我已经在 J​​enkins 中安装了 MSBuild 插件。在“全局工具配置”中,我添加了这样的 msbuild 路径:C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe

在构建阶段,我收到此错误:

MSBUILD:错误 MSB1009:项目文件不存在。

当我检查 Jenkins 工作区文件夹时,我可以看到所有项目文件(.sln 和 .csproj 文件)。我究竟做错了什么?

标签: jenkinsmsbuildjenkins-pipeline

解决方案


您可以尝试 MSBuild 路径如下所示:

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\amd64\MSBuild.exe

推荐阅读