0
0
Jenkinsdevops~30 mins

Multiple SCM repositories in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Managing Multiple SCM Repositories in Jenkins Pipeline
📖 Scenario: You are working on a Jenkins pipeline that needs to pull code from two different Git repositories. This is common when your project depends on multiple codebases that must be built or tested together.
🎯 Goal: Build a Jenkins pipeline script that checks out two separate Git repositories into different directories within the workspace.
📋 What You'll Learn
Use the checkout step to clone Git repositories
Clone the first repository into the default directory
Clone the second repository into a subdirectory named repo2
Use exact repository URLs: https://github.com/example/repo1.git and https://github.com/example/repo2.git
Print a message confirming both repositories are checked out
💡 Why This Matters
🌍 Real World
Many projects depend on multiple code repositories. Jenkins pipelines often need to pull code from several sources to build and test combined projects.
💼 Career
Knowing how to manage multiple SCM repositories in Jenkins is a key skill for DevOps engineers and CI/CD pipeline developers.
Progress0 / 4 steps
1
Setup first Git repository checkout
Create a Jenkins pipeline script that uses the checkout step to clone the Git repository from https://github.com/example/repo1.git into the default workspace directory.
Jenkins
Need a hint?

Use the checkout step with GitSCM class and specify the repository URL exactly.

2
Add second Git repository checkout with custom directory
Add a second checkout step to clone the Git repository from https://github.com/example/repo2.git into a subdirectory named repo2 inside the workspace. Use the dir step to specify the directory.
Jenkins
Need a hint?

Use the dir('repo2') step to change directory before checking out the second repository.

3
Add a stage to verify both repositories are checked out
Add a new stage named Verify Checkout that uses the sh step to run the shell command ls -l in the workspace root and inside the repo2 directory to list files and confirm both repositories are present.
Jenkins
Need a hint?

Use multiple sh steps to run ls -l commands in the root and repo2 directories.

4
Print confirmation message after checkout verification
Add a final step in the Verify Checkout stage that prints the message "Both repositories have been checked out successfully." using the echo step.
Jenkins
Need a hint?

Use the echo step to print the confirmation message exactly as given.