Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-58177

Leading - in workspace directory names mangled in multibranch pipeline

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • branch-api-plugin
    • None
    • jenkins-war:2.176.1
      branch-api-plugin: 2.5.2
    •  branch-api-2.5.3

      Apparently, some of our workspaces for specific branch names are mangled in a way that the directories start with a "-" (or multiple!). This would require some special handling in scripts and we would like to avoid that.

       

      There also have been some discussions about this special case in the now obsolete implementation in JENKINS-38706:

      https://issues.jenkins-ci.org/browse/JENKINS-38706?focusedCommentId=272733&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-272733

      https://issues.jenkins-ci.org/browse/JENKINS-38706?focusedCommentId=324422&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-324422

      https://issues.jenkins-ci.org/browse/JENKINS-38706?focusedCommentId=345815&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-345815

      https://issues.jenkins-ci.org/browse/JENKINS-38706?focusedCommentId=348257&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-348257

      I had a look and it seems to happen here:

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

       

      It can be tested with this small java program:

       

      import org.apache.commons.lang3.StringUtils;
      public class Test {
          public static void main(String args[]) {
              int MAX_LENGTH=32;
              String fullName= "JIRA-1054_rename_1234_to_abcdef_try2";
              String mnemonic = mnemonicOf(fullName);
              String path = StringUtils.right(mnemonic, MAX_LENGTH);
              System.out.println(path);
          }
          private static String mnemonicOf(String name) {
              // Do not need the complexity of NameMangler here, since we uniquify as needed.
              return name.replaceAll("(%[0-9A-F]{2}|[^a-zA-Z0-9-_.])+", "_");
          }
      }
      

      For the moment i have increased MAX_LENGTH on our jenkins, but I would really love to see this fixed in Jenkins.

          [JENKINS-58177] Leading - in workspace directory names mangled in multibranch pipeline

          Roman Pickl added a comment -

          jglick maybe you could have a look at it or share your opinion, as you have worked on JENKINS-2111.

          Roman Pickl added a comment - jglick maybe you could have a look at it or share your opinion, as you have worked on JENKINS-2111 .

          Jesse Glick added a comment -

          Would accept a tested patch to ensure that leading - does not appear, perhaps replaced by _, or just stripped if that leaves a valid name.

          Jesse Glick added a comment - Would accept a tested patch to ensure that leading - does not appear, perhaps replaced by _ , or just stripped if that leaves a valid name.

          Roman Pickl added a comment -

          thanks for the fast feedback. find a pull request here https://github.com/jenkinsci/branch-api-plugin/pull/161

          Roman Pickl added a comment - thanks for the fast feedback. find a pull request here https://github.com/jenkinsci/branch-api-plugin/pull/161

          Pierre Beitz added a comment -

          Release in branch-api-2.5.3

          Pierre Beitz added a comment - Release in  branch-api-2.5.3

            rompic Roman Pickl
            rompic Roman Pickl
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: