0
0
Jenkinsdevops~10 mins

Multiple SCM repositories in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Multiple SCM repositories
Start Jenkins Job
Load SCM Configurations
Checkout SCM Repo 1
Checkout SCM Repo 2
Run Build Steps
Complete Job
Jenkins loads multiple SCM repository settings, checks out each repository in order, then runs build steps.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Checkout') {
      steps {
        checkout([$class: 'GitSCM', userRemoteConfigs: [[url: 'https://repo1.git']]])
        checkout([$class: 'GitSCM', userRemoteConfigs: [[url: 'https://repo2.git']]])
      }
    }
  }
}
This Jenkins pipeline checks out two separate Git repositories sequentially.
Process Table
StepActionSCM Repo URLResultNotes
1Start Jenkins Job-Job startedInitial job trigger
2Load SCM Configurationshttps://repo1.git, https://repo2.gitConfigurations loadedBoth repo URLs read
3Checkout SCM Repo 1https://repo1.gitRepo 1 checked outWorkspace updated with repo1 files
4Checkout SCM Repo 2https://repo2.gitRepo 2 checked outWorkspace updated with repo2 files alongside repo1
5Run Build Steps-Build steps executedBuild uses files from both repos
6Complete Job-Job finished successfullyAll steps done
💡 Job ends after checking out both repositories and running build steps
Status Tracker
VariableStartAfter Step 3After Step 4Final
Workspace contentsemptyfiles from repo1files from repo1 + repo2files from repo1 + repo2
Key Moments - 2 Insights
Why do we see files from both repositories in the workspace after checkout?
Because Jenkins runs two separate checkout steps (see execution_table steps 3 and 4), it adds files from each repo into the workspace without removing the previous ones.
Does the second checkout overwrite the first repository's files?
No, the second checkout adds its files alongside the first repo's files, so both sets coexist in the workspace (execution_table step 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what happens at step 4?
ACheckout of the first repository
BCheckout of the second repository
CBuild steps execution
DJob completion
💡 Hint
Refer to the 'Action' and 'SCM Repo URL' columns in execution_table row 4
According to variable_tracker, what does the workspace contain after step 3?
AEmpty workspace
BFiles from repo2 only
CFiles from repo1 only
DFiles from both repo1 and repo2
💡 Hint
Check 'After Step 3' column for 'Workspace contents' in variable_tracker
If the second checkout was removed, how would the workspace contents change after the job?
AWorkspace would contain only repo1 files
BWorkspace would be empty
CWorkspace would contain only repo2 files
DWorkspace would contain files from both repos
💡 Hint
Look at variable_tracker and execution_table steps 3 and 4 to understand checkout effects
Concept Snapshot
Jenkins can checkout multiple SCM repositories by running multiple checkout steps.
Each checkout adds files to the workspace without removing previous ones.
Use separate checkout commands for each repo URL.
Build steps can then use files from all checked-out repos.
This allows combining code from different sources in one job.
Full Transcript
This visual execution shows how Jenkins handles multiple SCM repositories in one job. The job starts and loads configuration for two Git repositories. It then checks out the first repository, adding its files to the workspace. Next, it checks out the second repository, adding its files alongside the first. The workspace now contains files from both repositories. Build steps run using these combined files. Finally, the job completes successfully. The variable tracker confirms the workspace contents after each checkout. Key points include that each checkout adds files without overwriting previous ones, allowing multiple repos to coexist in the workspace.