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

git localBranch option does not work for empty string or "**"

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • job-dsl-plugin
    • None
    • OS: Linux amd64
      JRE: openjdk.x86_64 1.7.0 u55
      Jenkins 2.7.4
      Job DSL 1.49
      Git Plugin 2.5.2
      no slaves

      When using the localBranch option for git in DSL plugin with value "**" or "" (see documentation of "Check out to specific local branch" option in the Job configuration) together with mergeOptions, the build throws an exception:

      Merging Revision 43bd25e24c777330f07948e96672e006009e72d6 (origin/feature/myFeature) to origin/develop, UserMergeOptions{mergeRemote='origin', mergeTarget='develop', mergeStrategy='default', fastForwardMode='--ff'}
      14:13:49  > git rev-parse origin/develop^{commit} # timeout=10
      14:13:49  > git config core.sparsecheckout # timeout=10
      14:13:49  > git checkout -f origin/develop # timeout=10
      14:13:49  > git branch -a -v --no-abbrev # timeout=10
      14:13:49  > git checkout -b  origin/develop
      14:13:49 FATAL: Could not checkout  with start point origin/develop
      14:13:49 hudson.plugins.git.GitException: Could not checkout  with start point origin/develop
      14:13:49 	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2003)
      14:13:49 	at hudson.plugins.git.extensions.impl.PreBuildMerge.decorateRevisionToBuild(PreBuildMerge.java:70)
      14:13:49 	at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:998)
      14:13:49 	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1087)
      14:13:49 	at hudson.scm.SCM.checkout(SCM.java:495)
      14:13:49 	at hudson.model.AbstractProject.checkout(AbstractProject.java:1269)
      14:13:49 	at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:604)
      14:13:49 	at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
      14:13:49 	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
      14:13:49 	at hudson.model.Run.execute(Run.java:1741)
      14:13:49 	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:531)
      14:13:49 	at hudson.model.ResourceController.execute(ResourceController.java:98)
      14:13:49 	at hudson.model.Executor.run(Executor.java:410)
      14:13:49 Caused by: hudson.plugins.git.GitException: Command "git checkout -b  origin/develop" returned status code 128:
      14:13:49 stdout: 
      14:13:49 stderr: fatal: '' is no valid branch name.
      14:13:49 
      14:13:49 	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1723)
      14:13:49 	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:63)
      14:13:49 	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:1997)
      14:13:49 	... 12 more
      

      script:

      mavenJob("myJob") {
        scm {
          git {
            branch('origin/feature/*')
            remote {
              name('origin')
              url('ssh://git@mygitserver/myRepo')
            }
            extensions {
              cleanBeforeCheckout()
              pruneBranches()
              localBranch('')
              mergeOptions {
                remote('origin')
                branch('develop')
              }
            }
          }
        }
      }
      

      The XML generated by Job DSL plugin looks like this:

      <scm class="hudson.plugins.git.GitSCM">
      ...
        <extensions>
          <hudson.plugins.git.extensions.impl.LocalBranch>
            <localBranch></localBranch>
          </hudson.plugins.git.extensions.impl.LocalBranch>
          <hudson.plugins.git.extensions.impl.CleanBeforeCheckout/>
          <hudson.plugins.git.extensions.impl.PruneStaleBranch/>
          <hudson.plugins.git.extensions.impl.PreBuildMerge>
            <options>
               <mergeRemote>origin</mergeRemote>
               <mergeTarget>develop</mergeTarget>
               <mergeStrategy>default</mergeStrategy>
               <fastForwardMode>FF</fastForwardMode>
             </options>
          </hudson.plugins.git.extensions.impl.PreBuildMerge>
        </extensions>
      </scm>
      

      When I manually enter the empty string in job configuartion UI of jenkins (not with DSL script), then the inner Element "<localBranch>" is not added (just <hudson.plugins.git.extensions.impl.LocalBranch/>), which seems to fix the problem. I also tried to use "**" in the DSL script, with no luck.

      As workaround I omitted the localBranch option and instead added a config block (with all its disadvantages):

      configure {
        it / extensions << 'hudson.plugins.git.extensions.impl.LocalBranch' {}
      }
      

      I guess this might be more a bug in the git plugin, but I only have problems with generated Jobs, not with manual edits.

            daspilker Daniel Spilker
            svenackermann Sven Ackermann
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: