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

Branch Specifier regex fails - passed to git rev-parse?

    XMLWordPrintable

Details

    Description

      There is an issue with certain patterns passed using the : regex specifier.

      I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

      `:origin/release-\d

      {8}`

      Here is the output from the console using this pattern


      Started by user User Name
      Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
      > git rev-parse --is-inside-work-tree # timeout=10
      Fetching changes from the remote Git repository
      > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
      Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
      > git --version # timeout=10
      using .gitcredentials to set credentials
      > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
      > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/:refs/remotes/origin/
      > git config --local --remove-section credential # timeout=10
      > git rev-parse :origin/release-\d{8}

      ^

      {commit} # timeout=10
      > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit}

      # timeout=10
      > git rev-parse :origin/release-\d

      {8}

      ^

      {commit}

      # timeout=10
      ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
      Finished: FAILURE

      If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.

      Attachments

        Activity

          trii2054 Josh Johnston created issue -
          trii2054 Josh Johnston made changes -
          Field Original Value New Value
          Description There is an issue with certain patterns passed using the : regex specifier.

          I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

          `:origin/release-\d{8}`

          Here is the output from the console using this pattern

          Started by user User Name
          Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
           > git rev-parse --is-inside-work-tree # timeout=10
          Fetching changes from the remote Git repository
           > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
          Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
           > git --version # timeout=10
          using .gitcredentials to set credentials
           > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
           > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/*:refs/remotes/origin/*
           > git config --local --remove-section credential # timeout=10
           > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
           > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit} # timeout=10
           > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
          ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
          Finished: FAILURE


          If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.
          There is an issue with certain patterns passed using the : regex specifier.

          I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

          `:origin/release-\d{8}`

          Here is the output from the console using this pattern

              Started by user User Name
              Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
               > git rev-parse --is-inside-work-tree # timeout=10
              Fetching changes from the remote Git repository
               > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
              Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
               > git --version # timeout=10
              using .gitcredentials to set credentials
               > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
               > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/*:refs/remotes/origin/*
               > git config --local --remove-section credential # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
              ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
              Finished: FAILURE


          If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.
          trii2054 Josh Johnston added a comment - - edited

          I cloned the github repo and added a test to TestBranchSpec.java and it passes so it doesn't seem to be in there.

          TestBranchSpec.java
              public void testUsesJavaPatternWithRepetition() {
                  // match pattern from JENKINS-26842
              	BranchSpec m = new BranchSpec(":origin/release-\\d{8}");
              	assertTrue(m.matches("origin/release-20150101"));
              	assertFalse(m.matches("release-2015010"));
              	assertFalse(m.matches("release-201501011"));
              	assertFalse(m.matches("release-20150101-something"));
              }
          
          trii2054 Josh Johnston added a comment - - edited I cloned the github repo and added a test to TestBranchSpec.java and it passes so it doesn't seem to be in there. TestBranchSpec.java public void testUsesJavaPatternWithRepetition() { // match pattern from JENKINS-26842 BranchSpec m = new BranchSpec( ":origin/release-\\d{8}" ); assertTrue(m.matches( "origin/release-20150101" )); assertFalse(m.matches( "release-2015010" )); assertFalse(m.matches( "release-201501011" )); assertFalse(m.matches( "release-20150101-something" )); }
          trii2054 Josh Johnston made changes -
          Description There is an issue with certain patterns passed using the : regex specifier.

          I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

          `:origin/release-\d{8}`

          Here is the output from the console using this pattern

              Started by user User Name
              Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
               > git rev-parse --is-inside-work-tree # timeout=10
              Fetching changes from the remote Git repository
               > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
              Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
               > git --version # timeout=10
              using .gitcredentials to set credentials
               > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
               > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/*:refs/remotes/origin/*
               > git config --local --remove-section credential # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
              ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
              Finished: FAILURE


          If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.
          There is an issue with certain patterns passed using the : regex specifier.

          I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

          `:origin/release-\d{8}`

          Here is the output from the console using this pattern

          {code}
              Started by user User Name
              Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
               > git rev-parse --is-inside-work-tree # timeout=10
              Fetching changes from the remote Git repository
               > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
              Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
               > git --version # timeout=10
              using .gitcredentials to set credentials
               > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
               > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/*:refs/remotes/origin/*
               > git config --local --remove-section credential # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
              ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
              Finished: FAILURE

          {code}

          If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.
          trii2054 Josh Johnston made changes -
          Description There is an issue with certain patterns passed using the : regex specifier.

          I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

          `:origin/release-\d{8}`

          Here is the output from the console using this pattern

          {code}
              Started by user User Name
              Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
               > git rev-parse --is-inside-work-tree # timeout=10
              Fetching changes from the remote Git repository
               > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
              Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
               > git --version # timeout=10
              using .gitcredentials to set credentials
               > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
               > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/*:refs/remotes/origin/*
               > git config --local --remove-section credential # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
              ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
              Finished: FAILURE

          {code}

          If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.
          There is an issue with certain patterns passed using the : regex specifier.

          I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

          `:origin/release-\d{8}`

          Here is the output from the console using this pattern

          {noformat}
              Started by user User Name
              Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
               > git rev-parse --is-inside-work-tree # timeout=10
              Fetching changes from the remote Git repository
               > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
              Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
               > git --version # timeout=10
              using .gitcredentials to set credentials
               > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
               > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/*:refs/remotes/origin/*
               > git config --local --remove-section credential # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
              ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
              Finished: FAILURE

          {noformat}

          If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.
          trii2054 Josh Johnston made changes -
          Description There is an issue with certain patterns passed using the : regex specifier.

          I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

          `:origin/release-\d{8}`

          Here is the output from the console using this pattern

          {noformat}
              Started by user User Name
              Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
               > git rev-parse --is-inside-work-tree # timeout=10
              Fetching changes from the remote Git repository
               > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
              Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
               > git --version # timeout=10
              using .gitcredentials to set credentials
               > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
               > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/*:refs/remotes/origin/*
               > git config --local --remove-section credential # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit} # timeout=10
               > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
              ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
              Finished: FAILURE

          {noformat}

          If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.
          There is an issue with certain patterns passed using the : regex specifier.

          I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

          `:origin/release-\d{8}`

          Here is the output from the console using this pattern

          {noformat}
          Started by user User Name
          Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
           > git rev-parse --is-inside-work-tree # timeout=10
          Fetching changes from the remote Git repository
           > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
          Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
           > git --version # timeout=10
          using .gitcredentials to set credentials
           > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
           > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/*:refs/remotes/origin/*
           > git config --local --remove-section credential # timeout=10
           > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
           > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit} # timeout=10
           > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
          ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
          Finished: FAILURE
          {noformat}

          If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.
          trii2054 Josh Johnston made changes -
          Description There is an issue with certain patterns passed using the : regex specifier.

          I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

          `:origin/release-\d{8}`

          Here is the output from the console using this pattern

          {noformat}
          Started by user User Name
          Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
           > git rev-parse --is-inside-work-tree # timeout=10
          Fetching changes from the remote Git repository
           > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
          Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
           > git --version # timeout=10
          using .gitcredentials to set credentials
           > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
           > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/*:refs/remotes/origin/*
           > git config --local --remove-section credential # timeout=10
           > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
           > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit} # timeout=10
           > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
          ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
          Finished: FAILURE
          {noformat}

          If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.
          There is an issue with certain patterns passed using the : regex specifier.

          I am trying to match a branch with the format release-YYYYMMDD so I am using the following pattern

          `:origin/release-\d{8}`

          Here is the output from the console using this pattern

          {quote}
          Started by user User Name
          Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/kapx-site-demo/workspace
           > git rev-parse --is-inside-work-tree # timeout=10
          Fetching changes from the remote Git repository
           > git config remote.origin.url https://source.developers.google.com/p/kapx-site-demo # timeout=10
          Fetching upstream changes from https://source.developers.google.com/p/kapx-site-demo
           > git --version # timeout=10
          using .gitcredentials to set credentials
           > git config --local credential.helper store --file=/opt/bitnami/apache-tomcat/temp/git6326675135972302331.credentials # timeout=10
           > git -c core.askpass=true fetch --tags --progress https://source.developers.google.com/p/kapx-site-demo +refs/heads/*:refs/remotes/origin/*
           > git config --local --remove-section credential # timeout=10
           > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
           > git rev-parse refs/remotes/origin/:origin/release-\d{8}^{commit} # timeout=10
           > git rev-parse :origin/release-\d{8}^{commit} # timeout=10
          ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
          Finished: FAILURE
          {quote}

          If I change the pattern to something like this `:origin/release-\d*` it does not error, but it also is not specific enough since it would match any number of digits.
          markewaite Mark Waite added a comment -

          I am able to duplicate the bug. I can't currently explain (without debugger, etc.) why that "branch to build" definition with the leading colon (":origin/release-\d

          {8}") is passed to git rev-parse, since git rev-parse is not used to process regular expression based branch name matching.

          I also confirmed your work around of using ":origin/release-\d*" and an alternate work around using ":origin/release-\d{8}

          .*". Those are both only work arounds to the bug, since the trailing "

          {8}

          " is a perfectly valid syntax as far as I can tell.

          As your test shows, the problem does not seem to be in the BranchSpec matcher, but somewhere else in the plugin where it is deciding that it should not use the regular expression based branch name matcher, or it is failing a git rev-parse call prior to the branch name matching step.

          markewaite Mark Waite added a comment - I am able to duplicate the bug. I can't currently explain (without debugger, etc.) why that "branch to build" definition with the leading colon (":origin/release-\d {8}") is passed to git rev-parse, since git rev-parse is not used to process regular expression based branch name matching. I also confirmed your work around of using ":origin/release-\d*" and an alternate work around using ":origin/release-\d{8} .*". Those are both only work arounds to the bug, since the trailing " {8} " is a perfectly valid syntax as far as I can tell. As your test shows, the problem does not seem to be in the BranchSpec matcher, but somewhere else in the plugin where it is deciding that it should not use the regular expression based branch name matcher, or it is failing a git rev-parse call prior to the branch name matching step.
          trii2054 Josh Johnston added a comment -

          It may have something to do with the presence of a wildcard `*` in the pattern because `release-\d\d\d\d\d\d\d\d` also produces the same rev-parse error.

          trii2054 Josh Johnston added a comment - It may have something to do with the presence of a wildcard `*` in the pattern because `release-\d\d\d\d\d\d\d\d` also produces the same rev-parse error.
          trii2054 Josh Johnston added a comment -

          I think it is either here: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/util/DefaultBuildChooser.java#L52-L53
          or here https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java#L493-L494
          that causes it to use the regex matcher.

          I'm not really a java guy so I don't know how to get Jenkins running myself, let alone with a custom build of this plugin in order to test my theory. I'll see if I can find a unit test covering this case and verify my hunch that way.

          trii2054 Josh Johnston added a comment - I think it is either here: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/util/DefaultBuildChooser.java#L52-L53 or here https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java#L493-L494 that causes it to use the regex matcher. I'm not really a java guy so I don't know how to get Jenkins running myself, let alone with a custom build of this plugin in order to test my theory. I'll see if I can find a unit test covering this case and verify my hunch that way.
          trii2054 Josh Johnston made changes -
          Assignee Nicolas De Loof [ ndeloof ] Josh Johnston [ trii2054 ]
          trii2054 Josh Johnston added a comment - PR made against master https://github.com/jenkinsci/git-plugin/pull/302

          Code changed in jenkins
          User: Joshua Johnston
          Path:
          src/main/java/hudson/plugins/git/util/DefaultBuildChooser.java
          src/test/java/hudson/plugins/git/TestBranchSpec.java
          src/test/java/hudson/plugins/git/util/DefaultBuildChooserTest.java
          http://jenkins-ci.org/commit/git-plugin/94dff14649c5989677406ad1a19115560a812dc8
          Log:
          JENKINS-26842 Handle regex branch spec which does not contain '*'

          Apply code changes via patch ignoring mismatched whitespace

          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Joshua Johnston Path: src/main/java/hudson/plugins/git/util/DefaultBuildChooser.java src/test/java/hudson/plugins/git/TestBranchSpec.java src/test/java/hudson/plugins/git/util/DefaultBuildChooserTest.java http://jenkins-ci.org/commit/git-plugin/94dff14649c5989677406ad1a19115560a812dc8 Log: JENKINS-26842 Handle regex branch spec which does not contain '*' Apply code changes via patch ignoring mismatched whitespace
          markewaite Mark Waite added a comment -

          To be included in git plugin 2.3.5

          markewaite Mark Waite added a comment - To be included in git plugin 2.3.5
          markewaite Mark Waite made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]
          markewaite Mark Waite made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          markewaite Mark Waite added a comment -

          I confirmed this bug is fixed in the 2.3.6 snapshot version of the git plugin.

          The git plugin and git client plugin are being tested in hopes of releasing new versions before the end of June. If you're willing to assist with the testing, please download and install a pre-release build of the git client plugin and the git plugin. Problems detected in the pre-release should be e-mailed to MarkEWaite and ndeloof.

          I wrote some test ideas if you would like suggestions of areas that need testing. The git plugin supports many different use cases and its automated tests only evaluate a very few of those use cases.

          markewaite Mark Waite added a comment - I confirmed this bug is fixed in the 2.3.6 snapshot version of the git plugin. The git plugin and git client plugin are being tested in hopes of releasing new versions before the end of June. If you're willing to assist with the testing, please download and install a pre-release build of the git client plugin and the git plugin . Problems detected in the pre-release should be e-mailed to MarkEWaite and ndeloof . I wrote some test ideas if you would like suggestions of areas that need testing. The git plugin supports many different use cases and its automated tests only evaluate a very few of those use cases.
          markewaite Mark Waite added a comment -

          Fixed in git plugin 2.4.0 released 18 Jul 2015.

          markewaite Mark Waite added a comment - Fixed in git plugin 2.4.0 released 18 Jul 2015.
          rtyler R. Tyler Croy made changes -
          Workflow JNJira [ 161016 ] JNJira + In-Review [ 208420 ]

          People

            trii2054 Josh Johnston
            trii2054 Josh Johnston
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: