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

Leading - in workspace directory names mangled in multibranch pipeline

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: branch-api-plugin
    • Labels:
      None
    • Environment:
      jenkins-war:2.176.1
      branch-api-plugin: 2.5.2
    • Similar Issues:
    • Released As:
       branch-api-2.5.3

      Description

      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.

        Attachments

          Activity

          Hide
          rompic Roman Pickl added a comment -

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

          Show
          rompic Roman Pickl added a comment - Jesse Glick maybe you could have a look at it or share your opinion, as you have worked on JENKINS-2111 .
          Hide
          jglick 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.

          Show
          jglick 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.
          Hide
          rompic Roman Pickl added a comment -

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

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

          Release in branch-api-2.5.3

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

            People

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

              Dates

              • Created:
                Updated:
                Resolved: