In Jenkins, how to checkout a project into a specific directory (using GIT)

In the new Jenkins 2.0 pipeline (previously named the Workflow Plugin), this is done differently for:

  • The main repository
  • Other additional repositories

Here I am specifically referring to the Multibranch Pipeline version 2.9.

Main repository

This is the repository that contains your Jenkinsfile.

In the Configure screen for your pipeline project, enter your repository name, etc.

Do not use Additional Behaviors > Check out to a sub-directory. This will put your Jenkinsfile in the sub-directory where Jenkins cannot find it.

In Jenkinsfile, check out the main repository in the subdirectory using dir():

dir('subDir') {
    checkout scm
}

Additional repositories

If you want to check out more repositories, use the Pipeline Syntax generator to automatically generate a Groovy code snippet.

In the Configure screen for your pipeline project:

  1. Select Pipeline Syntax. In the Sample
    Step
    drop down menu, choose checkout: General SCM.
  2. Select your SCM system, such as Git. Fill in the usual information
    about your repository or depot.
  3. Note that in the Multibranch Pipeline, environment variable
    env.BRANCH_NAME contains the branch name of the main repository.
  4. In the Additional Behaviors drop down menu, select
    Check out to a sub-directory
  5. Click Generate Groovy. Jenkins will display the Groovy code snippet
    corresponding to the SCM checkout that you specified.
  6. Copy this code into your pipeline script or Jenkinsfile.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)