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

jgit fails to checkout specific branch

    XMLWordPrintable

Details

    Description

      To be able to do a proper release with the maven-release plugin, we need to be running the build on a clean checkout of a branch (not a detached HEAD).

      I'm trying to do this with the "Additional Behavior" "Check out to specifig local branch" (see screenshot).

      But when using jgit, I get this exception:

       
      Started by user admin
      [EnvInject] - Loading node environment variables.
      Building on master in workspace /Users/Shared/Jenkins/Home/jobs/dummy-tester/workspace
      Fetching changes from the remote Git repository
      Merging Revision 71099115b31453ae1d17e1808d46a7b6f8782fb4 (origin/master) onto /master
      FATAL: Unknown git object /master
      hudson.plugins.git.GitException: Unknown git object /master
      	at org.jenkinsci.plugins.gitclient.JGitAPIImpl.revParse(JGitAPIImpl.java:829)
      	at hudson.plugins.git.extensions.impl.PreBuildMerge.decorateRevisionToBuild(PreBuildMerge.java:60)
      	at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:765)
      	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:832)
      	at hudson.model.AbstractProject.checkout(AbstractProject.java:1387)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:676)
      	at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:581)
      	at hudson.model.Run.execute(Run.java:1593)
      	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:491)
      	at hudson.model.ResourceController.execute(ResourceController.java:88)
      	at hudson.model.Executor.run(Executor.java:247)
      

      When I change the "Branch name" from "master" to "origin/master", it does not fail, but it also does not checkout a branch (I used a shell step with "git branch" to check the branch I'm staying on):

       
      Building on master in workspace /Users/Shared/Jenkins/Home/jobs/dummy-tester-jgit/workspace
      Fetching changes from the remote Git repository
      Checking out Revision 71099115b31453ae1d17e1808d46a7b6f8782fb4 (origin/master)
      [workspace] $ /bin/sh -xe /var/folders/c1/m1rcv3kj7g5250lfh3frv_s800009c/T/hudson2838431825011865626.sh
      + git branch
      * (no branch)
        master
        null
        origin/master
      Parsing POMs
      [workspace] $ java -cp /Users/Shared/Jenkins/Home/plugins/maven-plugin/WEB-INF/lib/maven3-agent-1.3.jar:/Users/Shared/Jenkins/Home/tools/hudson.tasks.Maven_MavenInstallation/MVN_303/boot/plexus-classworlds-2.4.jar org.jvnet.hudson.maven3.agent.Maven3Main /Users/Shared/Jenkins/Home/tools/hudson.tasks.Maven_MavenInstallation/MVN_303 /Users/Shared/Jenkins/Home/war/WEB-INF/lib/remoting-2.28.jar /Users/Shared/Jenkins/Home/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-1.3.jar 49195
      Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
      <===[JENKINS REMOTING CAPACITY]===>channel started
      

      Doing the same (Branch name: "master) with cgit, I get this output, also telling that we really stay on a branch:

       
      Building on master in workspace /Users/Shared/Jenkins/Home/jobs/dummy-tester-cgit/workspace
      Fetching changes from the remote Git repository
      Fetching upstream changes from origin
      Checking out Revision 71099115b31453ae1d17e1808d46a7b6f8782fb4 (origin/master)
      First time build. Skipping changelog.
      [workspace] $ /bin/sh -xe /var/folders/c1/m1rcv3kj7g5250lfh3frv_s800009c/T/hudson1975846668439542655.sh
      + git branch
      * master
      Parsing POMs
      

      I also tried the same with the additional behavior "Merge before build", but the result is about the same.

      Attachments

        Activity

          please attach job config.xml
          looks like you have branch set to "/master", first slash make it invalid branch name

          ndeloof Nicolas De Loof added a comment - please attach job config.xml looks like you have branch set to "/master", first slash make it invalid branch name

          I couldn't reproduce the first problem of "Unknown git object /master", but I did reproduce the 2nd issue where jgit checks out the repository into the detached head state.

          Working on this.

          kohsuke Kohsuke Kawaguchi added a comment - I couldn't reproduce the first problem of "Unknown git object /master", but I did reproduce the 2nd issue where jgit checks out the repository into the detached head state. Working on this.

          Code changed in jenkins
          User: Kohsuke Kawaguchi
          Path:
          pom.xml
          src/test/java/hudson/plugins/git/GitSCMTest.java
          http://jenkins-ci.org/commit/git-plugin/33d7022b8e3c770c8f803549319aa0887df93ff5
          Log:
          JENKINS-19108 added a test case to verify the fix.

          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Kohsuke Kawaguchi Path: pom.xml src/test/java/hudson/plugins/git/GitSCMTest.java http://jenkins-ci.org/commit/git-plugin/33d7022b8e3c770c8f803549319aa0887df93ff5 Log: JENKINS-19108 added a test case to verify the fix.

          Where is my daemon to close this ticket when I need it!?

          kohsuke Kohsuke Kawaguchi added a comment - Where is my daemon to close this ticket when I need it!?

          Code changed in jenkins
          User: Kohsuke Kawaguchi
          Path:
          src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java
          src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java
          http://jenkins-ci.org/commit/git-client-plugin/43bf22c7c8b22ec0d22d1b0bb3ed12b6e304ac48
          Log:
          [FIXED JENKINS-19108]

          JGit was not honoring the branch in the checkoutBranch method

          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Kohsuke Kawaguchi Path: src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java http://jenkins-ci.org/commit/git-client-plugin/43bf22c7c8b22ec0d22d1b0bb3ed12b6e304ac48 Log: [FIXED JENKINS-19108] JGit was not honoring the branch in the checkoutBranch method

          People

            kohsuke Kohsuke Kawaguchi
            domi Dominik Bartholdi
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: