Challenge - 5 Problems
Multiple SCM Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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'
}
}
}
}
}Attempts:
2 left
💡 Hint
Think about where the checkout command places the files and what the 'dir' step does.
✗ Incorrect
The 'dir' step changes the working directory. The checkout inside 'dir('repo2')' clones repo2 into that folder. So 'ls -1' lists repo2's root contents.
❓ Configuration
intermediate2:00remaining
Declarative Pipeline: Correct Multiple SCM Checkout Syntax
Which Jenkins declarative pipeline snippet correctly checks out two different Git repositories into separate folders?
Attempts:
2 left
💡 Hint
Remember that each checkout inside a 'dir' block clones into that folder.
✗ Incorrect
Option A uses 'dir' to change folders and performs separate checkouts, which is the correct way to clone multiple repos into separate directories in declarative pipelines.
❓ Troubleshoot
advanced2: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?Attempts:
2 left
💡 Hint
Think about what happens if files from previous checkouts remain in the workspace.
✗ Incorrect
Git checkout errors with status 128 often happen when the workspace has leftover files causing conflicts. Cleaning the workspace before checkout usually fixes this.
🔀 Workflow
advanced2: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?
Attempts:
2 left
💡 Hint
You must checkout a repo before building it.
✗ Incorrect
You first checkout repo1, then build it, then checkout repo2, then build it. This ensures each build runs on the correct code.
✅ Best Practice
expert2: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?
Attempts:
2 left
💡 Hint
Think about security and automation in Jenkins pipelines.
✗ Incorrect
Storing credentials securely in Jenkins Credentials Manager and referencing them by ID in checkout steps is the recommended secure and automated approach.