Sometimes the workspace generated by a Multibranch Pipeline job starts with a ‘-’ which causes issues with scripts.
- CloudBees CI (CloudBees Core) on modern cloud platforms - Managed Master
- CloudBees CI (CloudBees Core) on traditional platforms - Client Master
- CloudBees Jenkins Enterprise - Managed Master
- CloudBees Jenkins Platform - Client Master
- CloudBees Jenkins Distribution
- Jenkins LTS
Branch API Plugin < 2.5.3
This issue comes from the way the Branch API Plugin was generating workspace directory names.
It was taking the git branch name and cutting it.
In case the git branch contained ‘-’ and the cut happened at the wrong place, it did not make sure the generated name did not start with a ‘-’.
A fix has been provided for this in version 2.5.3 of the Branch API Plugin.
In case updating to version 2.5.3 of the Branch API Plugin is not an option, you can add
-Djenkins.branch.WorkspaceLocatorImpl.PATH_MAX=<desired_workspace_length> to make sure the cut is done elsewhere (see How to add Java arguments to Jenkins? for details on adding this argument).
Important note: setting the value to 0 means unlimited length.
You might want to be careful with this setting as some environments don’t handle long paths well.
Refer to the documentation of your file system to know its specific limitations.