0
0
Jenkinsdevops~20 mins

Multiple SCM repositories in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 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.