Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Lab Manual: Creating a CI Pipeline Using Jenkins

Objective:
The objective of this lab is to guide the process of setting up a Continuous Integration (CI)
pipeline using Jenkins to automate the build and testing process of a sample application.

Prerequisites:
• Jenkins installed and accessible (Refer to the "Installing Jenkins on Azure Cloud"
lab manual)
• Sample application source code hosted in a version control system (e.g.,
GitHub)
• Basic understanding of Jenkins and version control systems

Lab Steps:

1. Access Jenkins Dashboard:


• Open a web browser and navigate to your Jenkins instance (e.g.,
http://localhost:8080).
• Log in with your Jenkins admin credentials.

2. Install Required Plugins:


• Navigate to Manage Jenkins > Manage Plugins > Available.
• Search for and install the following plugins if not already installed:
▪ Git Plugin
▪ Pipeline Plugin

3. Create a New Jenkins Pipeline:


• Navigate to New Item from the Jenkins dashboard.
• Enter a name for your pipeline (e.g., "SampleApp_CI_Pipeline").
• Choose **Pipeline** as the project type and click **OK**.

4. Configure Pipeline:
In the pipeline configuration page:
• Under General, define your pipeline description.
• Under Pipeline, select **Pipeline script from SCM** as the Definition.
• Choose your version control system (e.g., Git) and provide the repository
URL.
▪ Specify the branch to build (e.g., `main` or `master`).
▪ Save your configuration.

5. Create Jenkinsfile:
• In your source code repository, create a `Jenkinsfile` at the root level.
• Define your pipeline stages and steps in the `Jenkinsfile`. For example:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/your-username/sample-
app.git'
}
}
stage('Build') {
steps {
sh 'mvn clean package'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
}
// Add more stages as needed (e.g., Deploy, Publish Artifacts)
}
post {
always {
// Clean up or notify
}
success {
// Notify success
}
failure {
// Notify failure
}
}
}

6. Save and Run Pipeline:


• Once `Jenkinsfile` is configured, save it in repository.
• Go back to Jenkins dashboard and navigate to your pipeline.
• Click on Build Now to trigger the pipeline execution.

7. Monitor Pipeline Execution:


• Monitor the progress of your pipeline on the Jenkins dashboard.
• Click on the build number to view detailed logs of each stage.
• Troubleshoot any issues encountered during the build and testing
process.

8. Review Test Results:


• If your pipeline includes testing stages, review the test results to ensure
the application meets quality standards.
• Check for any failed tests and investigate the reasons for their failure.
9. Post-Build Actions (Optional):
• Configure post-build actions such as sending notifications, archiving
artifacts, or triggering downstream jobs based on build results.

10. Integration with Version Control System:


• Jenkins can automatically trigger pipeline builds on code changes pushed
to the repository. Ensure your pipeline is configured to listen for changes
and trigger builds accordingly.

Result:
In this lab, successfully created a Continuous Integration (CI) pipeline using Jenkins to
automate the build and testing process of a sample application. By integrating Jenkins
with version control systems, we established a robust CI workflow that enhances the
quality and reliability of your software projects.

You might also like