How to create s CI/CD pipeline in Jenkins

A CI/CD pipeline in Jenkins is a set of automated tasks that are used to build, test, and deploy software. Jenkins is an open-source automation server that can be used to implement CI/CD pipelines.

Jenkins logo
Jenkins logo

A typical CI/CD pipeline in Jenkins might consist of the following steps:

  • Source code checkout: The source code is checked out from a version control system, such as Git or Subversion.

  • Build: The source code is compiled and built into an executable or artifact.

  • Unit testing: The built artifact is unit tested to ensure that it meets the expected requirements.

  • Integration testing: The built artifact is integrated with other components of the system to ensure that it works as expected.

  • Deployment: The built artifact is deployed to a staging or production environment.

Creating a CI/CD pipeline

Creating a CI/CD (Continuous Integration/Continuous Deployment) pipeline in Jenkins involves several steps. Here's a general outline of the process:

  1. Install Jenkins:

  • Download and install Jenkins on your server or machine.

  • You can follow this Answer for installation instructions.

  1. Configure Jenkins and install required plugins:

  • Once Jenkins is installed, you need to Access its web interface and install certain plugins for specific functionalities required for your CI/CD pipeline.

  • Some commonly used plugins include Git, GitHub, Docker, Pipeline, etc.

  • You can follow this Answer for configuration instructions.

  1. Create a new pipeline:

  • Go back to the Jenkins dashboard and click on "New Item" on the left-hand side.

  • Enter a name for your pipeline and select "Pipeline" as the project type.

  • Click on "OK" to create the pipeline.

Click on Pipeline
Click on Pipeline

  1. Configure the pipeline script:

  • In the pipeline configuration, scroll down to the "Pipeline" section.

  • Under "Definition," select "Pipeline script from SCM".

  • Choose "Git" as the SCM and provide your GitHub repository URL.

  • Specify the branch (e.g., master) you want to build or use a wildcard pattern (e.g., */master) to trigger the pipeline on any branch's changes.

  • In the "Script Path" field, enter the path to your Jenkinsfile (pipeline script) in the repository. If it's in the root, simply enter "Jenkinsfile".

Pipeline script configuration
Pipeline script configuration
  1. Write the Jenkinsfile (pipeline script):

  • In your GitHub repository, create a file named "Jenkinsfile" (case-sensitive) at the root level.

  • This file will contain the pipeline script that defines the steps of your CI/CD process. You can use Groovy syntax for writing Jenkins pipeline scripts.

  • Here's a basic example Jenkinsfile to get you started:

pipeline {
agent any
stages {
stage('Build') {
steps {
// Your build steps here (e.g., compiling code, running tests)
}
}
stage('Deploy') {
steps {
// Your deployment steps here (e.g., deploying to a test server)
}
}
}
}
Jenkinsfile contents
  • Save the Jenkinsfile in your GitHub repository.

  1. Trigger the pipeline:

  • To trigger the pipeline, you can click on the "Build Now" button or you can schedule the pipeline .

Click on Build Now
Click on Build Now
  • Schedule the Pipeline:

    • In the pipeline configuration in Jenkins, scroll down to the "Build Triggers" section.

    • Check the "Build periodically" option.

    • Enter a cron expression to schedule your pipeline at specific intervals. For example, to run the pipeline every day at midnight, you can use 0 0 * * *.

Pipeline Scheduling
Pipeline Scheduling

  1. Save your Jenkins pipeline configuration.

Conclusion

With the steps mentioned above, you can set up a CI/CD pipeline in Jenkins that connects to your GitHub project, pulls the Jenkinsfile, and runs the defined stages on the specified schedule. The pipeline will be triggered based on changes in the specified branch or according to the scheduled cron expression.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved