[Multibranch] Add some other possibilities to set the folder name of the branch project

1,255 views
Skip to first unread message

Quentin Dufour

unread,
Jul 4, 2016, 11:45:08 AM7/4/16
to Jenkins Developers, que...@dufour.io
In Multibranch pipelines, it's currently impossible to choose the name of your branch project, and consequently the created folder name.
The name is generated from the branch name which is url encoded.

While it should probably work in most of the cases, we have encountered two major problems :
  • If the branch has a really long name, it will cause path too long execptions on Windows (our project).
  • When you have special characters in your branch such as /, they are url encoded. So you have folders with %2F in their name, which is not supported by some programs (I had some problems with msbuild).

I know that the sort answer would be : Use an Operating System which support long paths and programs which support non alphanumeric path, but it's not always possible.


There is a similarly issue on JIRA here : https://issues.jenkins-ci.org/browse/JENKINS-30744

The proposed fix did not work for me, as it didn't solve the problem. I've tried it with a UUID instead and had the following error :


FATAL: Failed to recompute children of MYPROJECT
java.lang.IllegalStateException: Name of created project org.jenkinsci.plugins.workflow.job.WorkflowJob@7eedefa0[p/1cbae353-d136-4d59-8406-7298d575da3a] did not match expected features%2Fmy-branch


Just to mention that it's not the right place to do the modification. Instead, the branch-api-plugin is an excellent candidate ! I just need to change the getEncodedName() function from Branch.java

https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/Branch.java#L101


In fact, I wanted to change the folder name for something which is not too long, has a fixed size, and only alphanumeric characters.
My solution was to create a md5 hash of the function and keep only the 8 first characters. (I'm using the function in the Util class from the Jenkins main project)

  public String getEncodedName() {
    return Util.getDigestOf(getName()).substring(0,8);
  }

https://github.com/superboum/branch-api-plugin/commit/1944cf052eff18bb7005660535081cab6b8f15f3


I've tested it on my jenkins and it works. But I'm conscious that I can't make a Pull Request of this change, as it breaks existing installations and Jenkins convention of naming folders.

However, applying this patch and compiling it for each version is really time consuming.


TL;DR


So my questions are :

  • Is there a way to implement a choice during the Multibranch Pipeline configuration to choose the naming policy of your branch folder (MY-PROJECT/f2a6f488 vs MY-PROJECT/features%2Fmy-branch) ?
  • Do you have an idea of which projects will be implicated by adding such a choice in the Jenkins Interface ?
  • And will a pull request like this has a chance of being accepted ?

Jesse Glick

unread,
Jul 6, 2016, 6:59:01 PM7/6/16
to Jenkins Dev
On Mon, Jul 4, 2016 at 11:45 AM, Quentin Dufour <mrsup...@gmail.com> wrote:
> If the branch has a really long name, it will cause path too long execptions
> on Windows (our project).

Well known, JENKINS-34564, use `dir` or `ws` steps as a workaround if
you cannot fix your tools.

Quentin Dufour

unread,
Aug 23, 2016, 3:36:23 PM8/23/16
to Jenkins Developers
I can't use dir or ws as this problem occurs during the first automatic checkout that fetch the Jenkinsfile in the multibranch pipeline. Somewhere where I can't set the path unfortunately.

Jesse Glick

unread,
Aug 23, 2016, 4:31:53 PM8/23/16
to Jenkins Dev
On Tue, Aug 23, 2016 at 3:36 PM, Quentin Dufour <mrsup...@gmail.com> wrote:
> I can't use dir or ws as this problem occurs during the first automatic
> checkout that fetch the Jenkinsfile

Pending work related to JENKINS-33273 (namely getting your `SCMSource`
to implement `SCMFileSystem`), the only option will be to implement
`WorkspaceLocator` I think.
Reply all
Reply to author
Forward
0 new messages