Using a Jenkins pipeline to checkout multiple git repos into same job
Here's Mine
stage('CheckoutModule1') {
steps {
sh 'mkdir -p Module1'
dir("Module1")
{
git branch: "develop",
credentialsId: 'aaa',
url: '[email protected]:b/module1.git'
}
}
}
stage('CheckoutModule2') {
steps {
sh 'mkdir -p Module2'
dir("Module2")
{
git branch: "develop",
credentialsId: 'aaa',
url: '[email protected]:b/module2.git'
}
}
}
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']]
])
}
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')
}
If your repository has submodules use git checkout
pipeline {
agent {label 'master'}
stages{
stage("Demo"){
steps{
echo 'Hello World'
}
}
stage("Source"){
parallel{
stage('CalibrationResults'){
steps{
echo 'Checking out CalibrationResults'
checkout([$class: 'GitSCM', branches: [[name: '*/CI-CD-Demo']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: true, reference: '', shallow: false, timeout: 60], [$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: false, recursiveSubmodules: true, reference: '', timeout: 60, trackingSubmodules: true], [$class: 'RelativeTargetDirectory', relativeTargetDir: 'server-core'],[$class: 'CheckoutOption', timeout: 60]], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/AtlasBID/CalibrationResults.git']]])
}
}
stage('Combination'){
steps{
echo 'Checking out server spoke'
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: true, reference: '', shallow: false, timeout: 60], [$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: false, recursiveSubmodules: true, reference: '', timeout: 60, trackingSubmodules: true], [$class: 'RelativeTargetDirectory', relativeTargetDir: 'server-spoke'], [$class: 'CheckoutOption', timeout: 60]], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/AtlasBID/CombinationBuilder.git']]])
}
}
}
}
}
}
Generated using Checkout git snippet generator