Jenkinsfile: how to checkout multiple branch sources in multibranch pipeline?

Viewed 951

I've configured multiple branch sources (different repositories) in multibranch pipeline: multiple branch sources

And in jenkinsfile I want to checkout all this repositories, I've tried next script:

node {
  stage("Checkout") {
    checkout scm
  }
}

But this script checkouts only first repository. How I can checkout all repositories in one step?

I know I can list all repositories by listing in jenkinsfile itself, but I want to use already provided branch sources.

1 Answers

This way you can checkout multiple repos in single jenkins build.

stage ('checkout'){
       cleanWs()
       dir ('app-code'){
       git branch: '${branch}', credentialsId: 'jenkins-gitlab', url: 'git@gitlab.xxx.net:xxx/xxx.git'
       }
       dir ('docker'){
           git branch: 'master', credentialsId: 'jenkins-gitlab', url: 'git@gitlab.xxx.net:xxx/docker-xxx.git'
       }
       dir ('charts'){
           git branch: 'master', credentialsId: 'jenkins-gitlab', url: 'git@gitlab.xxx.net:devops/xxx.git'
       }
   }
Related