CI-CD Pipeline in Jenkins
A CI/CD pipeline in Jenkins automates the process of building, testing, and deploying code. It helps developers integrate changes and deploy them quickly and reliably. Jenkins makes this automation easy and efficient.
Create CI-CD Pipeline in Jenkins
Here are the steps to create CI-CD Pipeline:
Step 1: Log In to Jenkins
Log in to your Jenkins account. This is where all your Jenkins jobs and pipelines will be configured and monitored.

Step 2: Redirected to the Jenkins Dashboard
When you logged in, you will be redirected to the Jenkins console or dashboard. This is where you can manage all your Jenkins jobs, pipelines, and settings.
Step 3: Create a New Project
On the Jenkins dashboard, click on the "New Item" option to create a new project select the option available in the Dashboard.
.jpg)
Step 4: Configure the Project Type
On the next screen, list of options will be visible, along with a field to name the pipeline. Add a suitable name and select the "Pipeline" option to proceed.
.png)
Step 5: Configure the General Section
The pipeline configuration page will open. In the General section:
- Provide a description of the pipeline, describing the purpose or what it will do.
- Establish the connection to the repository where Jenkins can access the project to trigger the pipeline.

Step 6: Set Build Triggers
In the Build Triggers section:
We need to specify the branch and repository and give the credentials too. And add additional behaviors if required so far. Refer to the screenshot to have a better understanding.

Step 7: Advanced Project Options
In the Advanced Project Options section:
- This section is primarily used for advanced configurations and special pipeline settings.
- For simpler projects, no configuration is required in this section, so you can leave it as is or adjust it based on your project's needs.

Step 8: Configure the Pipeline Section
This is the most critical part of the configuration process. In the Pipeline section:
- Define the Jenkinsfile that Jenkins will use to build and deploy your application. The Jenkinsfile contains the pipeline script with all the stages and steps for the CI/CD process.
- Specify where Jenkins should retrieve the pipeline script (either from the repository or from a file stored locally).
- Provide any required credentials or paths to the Jenkinsfile.
.png)
Sample Jenkins Pipeline Script
node {
// Define the Maven tool used for the build process
def mavenHome = tool name: 'Maven 3.8.6'
// Configure build properties (e.g., log rotation and SCM polling)
properties([
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '5', daysToKeepStr: '', numToKeepStr: '5')),
pipelineTriggers([pollSCM('* * * * *')])
])
// Checkout code from the Git repository
stage('Checkout Code') {
git branch: 'development', credentialsId: 'github-credentials-id', url: 'https://github.com/your-username/your-repository.git'
}
// Build the project using Maven
stage('Build') {
sh "${mavenHome}/bin/mvn clean package"
}
// Execute code quality analysis with SonarQube
stage('Execute SonarQube Analysis') {
sh "${mavenHome}/bin/mvn clean sonar:sonar"
}
// Upload the build artifact to Nexus repository
stage('Upload Build Artifact') {
sh "${mavenHome}/bin/mvn clean deploy"
}
// Deploy the application to Tomcat using SCP
stage('Deploy to Tomcat') {
sshagent(['your-ssh-credentials-id']) {
sh "scp -o StrictHostKeyChecking=no target/maven-web-application.war ec2-user@your-server:/opt/apache-tomcat-9.0.64/webapps/"
}
}
}
Step 9: Save the Pipeline and Run It
After writing the pipeline is done click on save it will be directly redirected to the Dashboard of the project there we can use, the "Build Now" option to run the pipeline and check if it is successful or not, by using stage view or console output.
.png)
Step 10: Monitor the Pipeline Execution
Once the pipeline is triggered, you can monitor its progress:
- Go to the Jenkins dashboard and click on your project.
- Under Build History, click on the build you just triggered.
- You can monitor the pipeline using the Stage View or Console Output.
Stage View: Provides a visual representation of the pipeline stages and their status (success, failure, etc.).
.png)
Console Output: Displays the detailed logs of each stage. This is useful for debugging any issues that may occur during the pipeline execution.
Step 11: Review the Build Status
At the bottom of the Console Output or Stage View, you will see the status of the pipeline:
- Success: If all stages are completed without errors, you will see "Finished: Success."
- Failure: If any stage fails, you will see error messages in the logs, which can help in debugging the issue.
.png)
.png)
Here we successfully created a Jenkins CI/CD pipeline to automate the process of building, testing, and deploying a Java web application .war file.