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

前端 未结 7 1016
面向向阳花
面向向阳花 2020-12-08 18:25

Sorry for the \'svn\' style - we are in a process of migration from SVN to GIT (including our CI Jenkins environment).

What we need is to be able to make Jenkins to

7条回答
  •  被撕碎了的回忆
    2020-12-08 18:44

    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.

提交回复
热议问题