Bird
Raised Fist0
Jenkinsdevops~20 mins

Multiple SCM repositories in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Multiple SCM Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Jenkins Pipeline: Multiple SCM Checkout Output
Consider this Jenkins pipeline snippet that checks out two Git repositories sequentially. What will be the output of the sh 'ls -1' command inside the dir('repo2') block?
Jenkins
pipeline {
  agent any
  stages {
    stage('Checkout Multiple Repos') {
      steps {
        dir('repo1') {
          checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/example/repo1.git']]])
        }
        dir('repo2') {
          checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/example/repo2.git']]])
          sh 'ls -1'
        }
      }
    }
  }
}
AA list of files and folders from the root of repo1 repository.
BAn empty output because the directory is empty.
CA Jenkins error indicating the directory 'repo2' does not exist.
DA list of files and folders from the root of repo2 repository.
Attempts:
2 left
💡 Hint
Think about where the checkout command places the files and what the 'dir' step does.
❓ Configuration
intermediate
2:00remaining
Declarative Pipeline: Correct Multiple SCM Checkout Syntax
Which Jenkins declarative pipeline snippet correctly checks out two different Git repositories into separate folders?
A
steps {
  dir('repo1') {
    checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/example/repo1.git']]])
  }
  dir('repo2') {
    checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/example/repo2.git']]])
  }
}
B
steps {
  checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/example/repo1.git']]])
  checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/example/repo2.git']]])
}
C
steps {
  checkout([$class: 'MultipleSCM', scms: [
    [$class: 'GitSCM', userRemoteConfigs: [[url: 'https://github.com/example/repo1.git']]],
    [$class: 'GitSCM', userRemoteConfigs: [[url: 'https://github.com/example/repo2.git']]]
  ]])
}
D
steps {
  dir('repo1') {
    git url: 'https://github.com/example/repo1.git'
  }
  git url: 'https://github.com/example/repo2.git'
}
Attempts:
2 left
💡 Hint
Remember that each checkout inside a 'dir' block clones into that folder.
❓ Troubleshoot
advanced
2:00remaining
Troubleshooting: Jenkins Pipeline Fails on Multiple SCM Checkout
A Jenkins pipeline with multiple SCM checkouts fails with the error: hudson.plugins.git.GitException: Command "git checkout -f refs/remotes/origin/main" returned status code 128. What is the most likely cause?
AThe Git repository URL is incorrect or unreachable.
BThe workspace folder is not clean and has conflicting files from previous checkouts.
CThe Jenkins agent does not have Git installed.
DThe pipeline syntax for multiple SCM checkout is invalid.
Attempts:
2 left
💡 Hint
Think about what happens if files from previous checkouts remain in the workspace.
🔀 Workflow
advanced
2:00remaining
Jenkins Pipeline: Correct Order of Steps for Multiple SCM Checkout and Build
What is the correct order of steps in a Jenkins pipeline stage that checks out two repositories and then builds the project?
A1,3,2,4
B1,2,3,4
C2,1,4,3
D2,4,1,3
Attempts:
2 left
💡 Hint
You must checkout a repo before building it.
✅ Best Practice
expert
2:00remaining
Best Practice: Managing Credentials for Multiple SCM Repositories in Jenkins
Which approach is the best practice for securely managing credentials when checking out multiple private Git repositories in a Jenkins pipeline?
AAsk users to enter credentials manually each time the pipeline runs.
BHardcode usernames and passwords directly in the pipeline script for each repository checkout.
CStore all credentials in Jenkins Credentials Manager and reference each by ID in the respective checkout step.
DUse the same credential ID for all repositories regardless of different access requirements.
Attempts:
2 left
💡 Hint
Think about security and automation in Jenkins pipelines.

Practice

(1/5)
1.

What is the main benefit of using multiple SCM repositories in a Jenkins job?

easy
A. It allows Jenkins to fetch code from several repositories in one build.
B. It speeds up the Jenkins server performance automatically.
C. It merges all repositories into a single repository permanently.
D. It restricts Jenkins to use only one branch per build.

Solution

  1. Step 1: Understand Jenkins SCM usage

    Jenkins uses SCM to get source code for building projects.
  2. Step 2: Identify multiple SCM benefit

    Multiple SCM lets Jenkins pull from many repositories in one job, useful for projects with dependencies.
  3. Final Answer:

    It allows Jenkins to fetch code from several repositories in one build. -> Option A
  4. Quick Check:

    Multiple SCM = fetch multiple repos [OK]
Hint: Multiple SCM means multiple code sources in one job [OK]
Common Mistakes:
  • Thinking it merges repos permanently
  • Assuming it improves server speed
  • Believing it limits branches
2.

Which Jenkins pipeline syntax correctly defines two SCM repositories using checkout steps?

<pre>1) checkout([$class: 'GitSCM', userRemoteConfigs: [[url: 'https://repo1.git']]]) checkout([$class: 'GitSCM', userRemoteConfigs: [[url: 'https://repo2.git']]]) 2) checkout([$class: 'GitSCM', userRemoteConfigs: [[url: 'https://repo1.git', url: 'https://repo2.git']]]) 3) checkout([$class: 'GitSCM', url: 'https://repo1.git']) checkout([$class: 'GitSCM', url: 'https://repo2.git']) 4) checkout([$class: 'GitSCM', userRemoteConfigs: ['https://repo1.git', 'https://repo2.git']])

easy
A. Option 1
B. Option 2
C. Option 3
D. Option 4

Solution

  1. Step 1: Check syntax for multiple SCM in Jenkins pipeline

    Each checkout step handles one SCM repo; multiple repos require multiple checkout calls.
  2. Step 2: Analyze options

    Option 1 uses two separate checkout calls with correct userRemoteConfigs. Option 2 tries to combine repos in one config incorrectly. Option 3 uses wrong key url directly. Option 4 uses wrong list format.
  3. Final Answer:

    Option 1 -> Option A
  4. Quick Check:

    Separate checkout per repo = Option 1 [OK]
Hint: Use separate checkout steps for each repo [OK]
Common Mistakes:
  • Combining multiple URLs in one userRemoteConfigs entry
  • Using 'url' key instead of userRemoteConfigs
  • Passing URLs as plain list without map
3.

Given this Jenkins pipeline snippet, what will be the result?

stage('Checkout') {
  steps {
    checkout([$class: 'GitSCM', userRemoteConfigs: [[url: 'https://repo1.git']]])
    checkout([$class: 'GitSCM', userRemoteConfigs: [[url: 'https://repo2.git']]])
  }
}

Choose the correct statement about the workspace after this stage runs.

medium
A. The workspace contains code from both repo1 and repo2 in separate folders.
B. The workspace contains only repo2 code, repo1 is overwritten.
C. The workspace contains merged files from repo1 and repo2 in the root folder.
D. The build will fail due to multiple checkout commands.

Solution

  1. Step 1: Understand default checkout behavior

    By default, Jenkins checks out each repo into the same workspace folder, overwriting previous content.
  2. Step 2: Analyze the effect of two checkout calls

    The second checkout replaces the first repo's files because both use the root workspace folder without specifying subdirectories.
  3. Final Answer:

    The workspace contains only repo2 code, repo1 is overwritten. -> Option B
  4. Quick Check:

    Multiple checkout without directories overwrites workspace [OK]
Hint: Without directories, last checkout overwrites workspace [OK]
Common Mistakes:
  • Assuming repos merge automatically
  • Thinking Jenkins creates subfolders by default
  • Believing multiple checkouts cause build failure
4.

In a Jenkins job configured with multiple SCM repositories, the build fails with this error: hudson.plugins.git.GitException: Command "git clone" failed. What is the most likely cause?

medium
A. The workspace directory is not cleaned before checkout.
B. The Jenkins server has no internet connection.
C. The Jenkinsfile syntax is invalid.
D. The userRemoteConfigs list is empty or missing URLs.

Solution

  1. Step 1: Understand the error context

    Git clone failure usually means the repository URL is invalid or missing.
  2. Step 2: Check multiple SCM config

    If userRemoteConfigs is empty or missing URLs, Jenkins cannot clone repos, causing this error.
  3. Final Answer:

    The userRemoteConfigs list is empty or missing URLs. -> Option D
  4. Quick Check:

    Missing repo URLs cause git clone failure [OK]
Hint: Check repo URLs in userRemoteConfigs first [OK]
Common Mistakes:
  • Blaming workspace cleanup for git clone errors
  • Assuming Jenkinsfile syntax causes git clone failure
  • Ignoring network issues as cause
5.

You want to configure a Jenkins pipeline to checkout two Git repositories into separate folders repo1 and repo2 inside the workspace. Which pipeline snippet correctly achieves this?

checkout([$class: 'GitSCM', userRemoteConfigs: [[url: 'https://repo1.git']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'repo1']]])
checkout([$class: 'GitSCM', userRemoteConfigs: [[url: 'https://repo2.git']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'repo2']]])
hard
A. This snippet merges both repos into the root workspace folder.
B. This snippet will fail because RelativeTargetDirectory is not supported.
C. This snippet correctly checks out both repos into separate folders.
D. This snippet only checks out the first repo; second is ignored.

Solution

  1. Step 1: Understand RelativeTargetDirectory extension

    This extension tells Jenkins to checkout the repo into a specified subfolder inside the workspace.
  2. Step 2: Analyze the snippet

    Each checkout uses RelativeTargetDirectory with different folder names, so repos go into separate folders without overwriting.
  3. Final Answer:

    This snippet correctly checks out both repos into separate folders. -> Option C
  4. Quick Check:

    RelativeTargetDirectory separates repos in workspace [OK]
Hint: Use RelativeTargetDirectory to separate repos in workspace [OK]
Common Mistakes:
  • Not using RelativeTargetDirectory causes overwriting
  • Assuming Jenkins merges repos automatically
  • Believing second checkout is ignored
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard