I think this is the same issue I am getting. We changed the standard jenkins artifact publisher to use sftp as we have a lot of compile output and sftp is much quicker.
I have a branch called CDU-009_hi_john and am running a Jenkins multibranch pipeline build. My sftp needs to cd to the directory that will contain the outputs and that is failing as the directory does not exist. After investigation I see that jenkins has created the following directory:
/var/lib/jenkins/jobs/CDM-Project/jobs/CDM-MultiBranch-Pipeline/branches/CDU-009-hi-john.2ujcja/builds/10/archive
Jenkins changes the underscores to hyphens and adds a weird 6 character string to the end. Looking at all my other pipelines this seems to be consistent behaviour, but is only an issue on the pipelines that I want to use sftp (larger output to return).
I wondered if there was a jenkins environment variable that might tell me where Jenkins is putting stuff but have listed all the obvious one:
{{{}}}
10:16:18 echo jenkinsHome /var/lib/jenkins
10:16:18 echo jobName /var/lib/jenkins/jobs/CDM-Project/CDM-MultiBranch-Pipeline/CDU-009_hi_john/
10:16:18 echo jobBaseName CDU-009_hi_john
10:16:18 echo jobUrl http:
{{ }}
Of course, if I use hyphens in the branch name I have no problem. So I can make that a naming condition, but don't want to be so restrictive.
It uses double encoding of the URL to escape non-URL safe characters as these characters may not be compatible with all filesystems.
The best practice here would be to create an archive (zip/tar/etc) and publish it directly to an artifact repository like SonaType Nexus or JFrog Artifactory.
If you just want to use plain old Jenkins, I'd use a archive (zip/tar/etc) with a well known name.