7
votes

When I try to msbuild a Multi-Branch Project in Jenkins, the build fails because msbuild replace the escape "%2F" with "\"

Example error:

"C:\Program Files (x86)\Jenkins\jobs\ProjectBranches\branches\branches%2FBranch-229\workspace\project\project\project.csproj" (default target) (1) -> C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.CurrentVersion.targets(321,5): error MSB4019: The imported project "C:\Program Files (x86)\Jenkins\jobs\ProjectBranches\branches\branches\Branch-229\workspace\project\packages\Microsoft.Net.Compilers.1.0.0\tools\Microsoft.CSharp.Core.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. [C:\Program Files (x86)\Jenkins\jobs\ProjectBranches\branches\branches%2FBranch-229\workspace\project\project\project.csproj]

2

2 Answers

2
votes

There is a whole discussion about branch name encoding in Jira #34564.

A propsed work-around that works for me is to change workspace dir in Jenkinsfile:

node(agent) {

    def workspace_orig = pwd()
    def workspace_sane = workspace_orig.replaceAll("%", "_")

    ws(workspace_sane) {
        // ...
    }

}
0
votes

I just encountered this issue today. I ended up solving by overriding the build and workspace folder in the server configuration

I set "Workspace Root Directory" to "c:/ws/${ITEM_FULL_NAME}/work" and the "Build Record Root Directory" to "c:/ws/${ITEM_FULL_NAME}/builds"

The ITEM_FULL_NAME is the name of the job, and since the name of the job has a "/" instead of the %2F it will end up making the folder similar to c:\ws\project\branch\name\work. That should resolve your issue.