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

notifyCommit branch parameter can't contain slashes

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • git-plugin
    • Jenkins 1.620, Git Plugin 2.4.0

      I have a simple Jenkins job called "myjob":

      Repository URL: git://github.com/jenkinsci/git-client-plugin.git
      Branches to build: tests/getSubmodules
      Build Triggers > Poll SCM is enabled

      I execute

      curl -s http://myjenkinssrv/jenkins/git/notifyCommit -d url=git://github.com/jenkinsci/git-client-plugin.git -d branches=tests/getSubmodules

      and I get

      No git jobs using repository: git://github.com/jenkinsci/git-client-plugin.git and branches: tests/getSubmodules

      This is wrong! If I configure my job with "Branches to build"=master and call

      curl -s http://myjenkinssrv/jenkins/git/notifyCommit -d url=git://github.com/jenkinsci/git-client-plugin.git -d branches=master

      it works, as expected.

          [JENKINS-29603] notifyCommit branch parameter can't contain slashes

          Ludwig Arnesen created issue -

          I can reproduce this issue, and it is critical for me. I will attempt to contribute a test, and a fix if I can.

          If someone could help me at first by showing me how to enable the verbosity of all the listener.getLogger() calls that would help me. I already know how to setup the log recorder in jenkins to catch all the hudson.plugins.git messages, and I already know to start jenkins with verbosity enabled java -Dhudson.plugins.git.GitSCM.verbose=true -jar jenkins.war

          Martin d'Anjou added a comment - I can reproduce this issue, and it is critical for me. I will attempt to contribute a test, and a fix if I can. If someone could help me at first by showing me how to enable the verbosity of all the listener.getLogger() calls that would help me. I already know how to setup the log recorder in jenkins to catch all the hudson.plugins.git messages, and I already know to start jenkins with verbosity enabled java -Dhudson.plugins.git.GitSCM.verbose=true -jar jenkins.war

          Mark Waite added a comment -

          If you change the argument value to origin/tests/getSubmodules, does it behave better?

          Mark Waite added a comment - If you change the argument value to origin/tests/getSubmodules, does it behave better?

          Martin d'Anjou added a comment - - edited

          Setting "Branches to build" to origin/tests/getSubmodules. Result:

          $ curl -s http://localhost:8080/git/notifyCommit \
            -d url=ssh://git@localhost:7999/project/veelox.git \
            -d branches=tests/getSubmodules
          Scheduled polling of VeeloxStash � veeloxstash-prbuild
          

          Your suggestion worked.

          If the notification contains the alias name of the repository, it does not work:

          $ curl -s http://localhost:8080/git/notifyCommit \
            -d url=ssh://git@localhost:7999/project/veelox.git \
            -d branches=origin/tests/getSubmodules
          No git jobs using repository: ssh://git@localhost:7999/project/veelox.git and branches: origin/tests/getSubmodules
          

          So it seems that the BRANCH_NAME in &branches=BRANCH_NAME is prefixed by the alias name of the repository (I have tried origin, upstream, and an empty name), before the Git Plugin scans the jobs for candidates. Looks like this is a documentation issue. I admit I am often confused myself by the Git Plugin documentation.

          Martin d'Anjou added a comment - - edited Setting "Branches to build" to origin/tests/getSubmodules . Result: $ curl -s http://localhost:8080/git/notifyCommit \ -d url=ssh://git@localhost:7999/project/veelox.git \ -d branches=tests/getSubmodules Scheduled polling of VeeloxStash � veeloxstash-prbuild Your suggestion worked. If the notification contains the alias name of the repository, it does not work: $ curl -s http://localhost:8080/git/notifyCommit \ -d url=ssh://git@localhost:7999/project/veelox.git \ -d branches=origin/tests/getSubmodules No git jobs using repository: ssh://git@localhost:7999/project/veelox.git and branches: origin/tests/getSubmodules So it seems that the BRANCH_NAME in &branches=BRANCH_NAME is prefixed by the alias name of the repository (I have tried origin , upstream , and an empty name), before the Git Plugin scans the jobs for candidates. Looks like this is a documentation issue. I admit I am often confused myself by the Git Plugin documentation.

          Mark Waite added a comment -

          Yes, the documentation has a very difficult task, describing something with more edge cases and conditionals than make me comfortable. I've preferred to focus my efforts on writing tests to enumerate the edge cases rather than writing documentation to describe the edge cases.

          This is a most interesting condition for which (I believe) there is no unit test to show the behavioral oddity you've detected. I'm not entirely sure how to write a test for this case.

          Mark Waite added a comment - Yes, the documentation has a very difficult task, describing something with more edge cases and conditionals than make me comfortable. I've preferred to focus my efforts on writing tests to enumerate the edge cases rather than writing documentation to describe the edge cases. This is a most interesting condition for which (I believe) there is no unit test to show the behavioral oddity you've detected. I'm not entirely sure how to write a test for this case.

          Martin d'Anjou added a comment - - edited

          This code prefixes the repository name to the branch name:
          https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitStatus.java#L266

          It makes sense to NOT use the remote repository name when composing the notifyCommit HTTP GET branches parameter. The external world is not supposed to know what names will be used inside the Git Plugin configuration.

          On the other hand, there are eight documented formats for the branches to build:

          1. <branchName>
          2. refs/heads/<branchName>
          3. <remoteRepoName>/<branchName>
          4. remotes/<remoteRepoName>/<branchName>
          5. refs/remotes/<remoteRepoName>/<branchName>
          6. ${ENV_VARIABLE}
          7. <Wildcards>
          8. :<regular expression>

          According to the code in BranchSpec.java and GitStatus.java, I think the first two will never work with notifyCommit. The last three may work if constructed properly. So is this issue a bug? I think it can be addressed with proper documentation in the wiki and perhaps in the help text of the plugin. As for writing tests, I agree that it is necessary.

          Martin d'Anjou added a comment - - edited This code prefixes the repository name to the branch name: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitStatus.java#L266 It makes sense to NOT use the remote repository name when composing the notifyCommit HTTP GET branches parameter. The external world is not supposed to know what names will be used inside the Git Plugin configuration. On the other hand, there are eight documented formats for the branches to build: <branchName> refs/heads/<branchName> <remoteRepoName>/<branchName> remotes/<remoteRepoName>/<branchName> refs/remotes/<remoteRepoName>/<branchName> ${ENV_VARIABLE} <Wildcards> :<regular expression> According to the code in BranchSpec.java and GitStatus.java , I think the first two will never work with notifyCommit . The last three may work if constructed properly. So is this issue a bug? I think it can be addressed with proper documentation in the wiki and perhaps in the help text of the plugin. As for writing tests, I agree that it is necessary.

          Is it possible to fix this problem? I use /ref/heads/... or /ref/tags/... in the "Branches to build" input field to build from branches or tags. It can happen that a user moves a tag which means the git server calls notifyCommit to trigger a new build. If I have to use "origin" as a prefix (which is not very intuitive) in the "Branches to build" field I cannot build from tags.

          Ludwig Arnesen added a comment - Is it possible to fix this problem? I use /ref/heads/... or /ref/tags/... in the "Branches to build" input field to build from branches or tags. It can happen that a user moves a tag which means the git server calls notifyCommit to trigger a new build. If I have to use "origin" as a prefix (which is not very intuitive) in the "Branches to build" field I cannot build from tags.
          Ludwig Arnesen made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Ludwig Arnesen made changes -
          Status Original: In Progress [ 3 ] New: Open [ 1 ]

          Warren Seine added a comment - - edited

          I'm also experiencing this issue.

          I already had this issue with The BFG (a Java tool to filter a Git repository) and it was fixed. Are you using the same Git library?

          See the issue here: https://github.com/rtyley/bfg-repo-cleaner/issues/34

          Warren Seine added a comment - - edited I'm also experiencing this issue. I already had this issue with The BFG (a Java tool to filter a Git repository) and it was fixed . Are you using the same Git library? See the issue here: https://github.com/rtyley/bfg-repo-cleaner/issues/34

            Unassigned Unassigned
            ludwig Ludwig Arnesen
            Votes:
            5 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated: