Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Jenkins JobDSL to set 'Check out to specific local branch' in Git Plugin?

I have the following:

job {
  scm {
    git {
      remote {
        url(GIT_URL)
      }
      branch('master')
    }
  }
}

It works pretty well but I would like for it to set 'Check out to specific local branch' to 'master'. How is that done?

I didn't find anything in https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java that pointed to anything that can be used but I may have missed something.

like image 548
Noel Yap Avatar asked Jan 13 '15 19:01

Noel Yap


2 Answers

Since the accepted answer was written, support for 'Check out to specific local branch' has been added:

job {
  scm {
    git {
      remote {
        url(GIT_URL)
      }
      branch('master')

      extensions {
        localBranch 'master'
      }
    }
  }
}
like image 82
samlewis Avatar answered Sep 20 '22 03:09

samlewis


That option is currently not supported by the Job DSL, but you can use a configure block to modify the generated config XML:

job {
  scm {
    git {
      remote {
        url(GIT_URL)
      }
      branch('master')
      configure { node ->
        node / 'extensions' << 'hudson.plugins.git.extensions.impl.LocalBranch' {
          localBranch('master')
        }
      }
    }
  }
}
like image 43
daspilker Avatar answered Sep 22 '22 03:09

daspilker