When I build a job using Multibranch pipeline, Jenkins is not creating workspace repository which is more than 32 character. It trims the character from starting of the job name.
Job name: multi-branch-jenkins-pipeline
Branch: Dev
what i want jenkins to create workspace: multi-branch-jenkins-pipeline_dev
what Jenkins create: iple-branch-jenkins-pipeline_dev
What i tried Djenkins.branch.WorkspaceLocatorImpl.PATH_MAX=40 Didn’t Work
Jenkins 2.332.1 switched Jenkins from using System V init to use systemd with its Linux package installers for Debian, Ubuntu, Red Hat, Alma, openSUSE, Rocky, and more. The LTS Upgrade Guide describes that transition and how to adapt your environment to the transition.
However the core question was asked earlier: why do you need the workspace name to match the job name?
On one hand, the limit is there for portability - various OSes limit the lengths of path components and full path names, so allowing names too long opens the door for failed builds just because files in a deeply nested workspace may no longer be addressed.
On another, predictable names are an attack vector, potentially. Though I don’t think Jenkins deliberately “protects” from that.
In case of allowed parallel builds, you would have several workspaces instantiated with similar-looking but different names (often “prefix@number”), and in case of branch builds (as with MBPs) part of the name will refer to the branch name, PR number, etc.
There could have been various algorithms to craft the unique directory name over time, but generally it takes the tail of the build identifier (job name + number) as a more likely varied character sequence than a start of same string, and might pepper with random chars like mktemp would.
All that said, there is a place in the ecosystem for persistent workspaces, maybe even such that pass some sort of “state” files between rebuilds (infra jobs, stats, whatever). While this is better tracked elsewhere (DB, fileserver), a Jenkins workspace might be used for the purpose. In that case you should not really care about the particular name (might add a conveniently named symlink to the directory if something outside Jenkins needs to tap into the directory), but should take care to disable parallel builds so “prefix@2” etc. are not used - thus ignoring the pre-history state you try to pass around.
The plugin caches the paths in the file workspaces.txt found in the directory workspace under the agents root but also in memory. So you would need to delete that file first on all agents if you have static agents and then run in the script console jenkins.branch.WorkspaceLocatorImpl.indexCache().clear()
thank you - it seems works after deleting file workspaces.txt and clearing cache, but it works only if I run this from Jenkins script console: jenkins.branch.workspaceLocatorImpl.MAX_LENGTH=64
But any other variants to add this to jenkins service for permanent applying doesnt work.
I’ve add it into /etc/sysconfig/jenkins