Using a Jenkins pipeline to checkout multiple git repos into same job Using a Jenkins pipeline to checkout multiple git repos into same job jenkins jenkins

Using a Jenkins pipeline to checkout multiple git repos into same job


You can use the dir command to execute a pipeline step in a subdirectory:

node('ATLAS && Linux') {    dir('CalibrationResults') {        git url: 'https://github.com/AtlasBID/CalibrationResults.git'    }    dir('Combination') {        git url: 'https://github.com/AtlasBID/Combination.git'    }    dir('CombinationBuilder') {        git url: 'https://github.com/AtlasBID/CombinationBuilder.git'    }    sh('ls')    sh('. CombinationBuilder/build.sh')}


You can checkout those three git repositories into three subdirectories by using the checkout SCM step three times like this:

stage('Checkout') { // Get CalibrationResults from GitHub checkout([              $class: 'GitSCM',             branches: [[name: 'refs/heads/master']],             doGenerateSubmoduleConfigurations: false,             extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'CalibrationResults']],             submoduleCfg: [],             userRemoteConfigs: [[credentialsId: '6463627-ab54-4e42-bc29-123458', url: 'https://github.com/AtlasBID/CalibrationResults.git']]        ]) // Get Combination from GitHub checkout([              $class: 'GitSCM',             branches: [[name: 'refs/heads/master']],             doGenerateSubmoduleConfigurations: false,             extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'Combination']],             submoduleCfg: [],             userRemoteConfigs: [[credentialsId: '6463627-ab54-4e42-bc29-123458', url: 'https://github.com/AtlasBID/Combination.git']]        ]) // Get CombinationBuilder from GitHub checkout([              $class: 'GitSCM',             branches: [[name: 'refs/heads/master']],             doGenerateSubmoduleConfigurations: false,             extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'CombinationBuilder']],             submoduleCfg: [],             userRemoteConfigs: [[credentialsId: '6463627-ab54-4e42-bc29-123458', url: 'https://github.com/AtlasBID/CombinationBuilder.git']]        ])}


Here's Mine

    stage('CheckoutModule1') {        steps {            sh 'mkdir -p Module1'            dir("Module1")            {                git branch: "develop",                credentialsId: 'aaa',                url: 'git@a.com:b/module1.git'            }        }    }    stage('CheckoutModule2') {        steps {            sh 'mkdir -p Module2'            dir("Module2")            {                git branch: "develop",                credentialsId: 'aaa',                url: 'git@a.com:b/module2.git'            }        }    }