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:
- Select Pipeline Syntax. In the Sample
Step drop down menu, choose checkout: General SCM.
- Select your SCM system, such as Git. Fill in the usual information
about your repository or depot.
- Note that in the Multibranch Pipeline, environment variable
env.BRANCH_NAME
contains the branch name of the main repository.
- In the Additional Behaviors drop down menu, select
Check out to a sub-directory
- Click Generate Groovy. Jenkins will display the Groovy code snippet
corresponding to the SCM checkout that you specified.
- Copy this code into your pipeline script or
Jenkinsfile
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…