DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones Build AI Agents That Are Ready for Production
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
Build AI Agents That Are Ready for Production

"Platform Engineering & DevOps" Trend Report is now LIVE! Learn how internal platforms help developers ship faster with less friction

AI-ready data starts with modernization. Join DZone + Informatica live on 6/16 at 1 PM ET.

Join this live webinar to learn safer rollout techniques for schema changes, index testing, and database migrations.

Related

  • Implementing CI/CD Pipelines With Jenkins and Docker
  • Getting Started With Jenkins
  • Autonomous Pipelines: Transforming CI/CD With Full Automation
  • Rethinking the Software Supply Chain for Agents

Trending

  • Prompt Injection Is Real, So I Built a Python Firewall for LLM Pipelines
  • Rust-Native Alternatives to Spark SQL and DataFrame Workloads
  • How to Build an Agentic AI SRE Co-Pilot for Incident Response
  • Logging What AI Agents Do in Salesforce: A Simple One-Object Audit Framework
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. How To Implement CI/CD for Multibranch Pipeline in Jenkins

How To Implement CI/CD for Multibranch Pipeline in Jenkins

In this guide, explore the process of creating a Jenkins multibranch pipeline project and configuring it with the Git repo.

By 
Krishna Prasad Kalakodimi user avatar
Krishna Prasad Kalakodimi
·
Updated by 
Tariq Siddiqui user avatar
Tariq Siddiqui
·
Updated Mar. 29, 24 · Tutorial
Likes (16)
Comment
Save
Tweet
Share
95.9K Views

Join the DZone community and get the full member experience.

Join For Free

Jenkins is a Continuous Integration (CI) server that can fetch the latest code from the version control system (VCS), build it, test it, and notify developers. Jenkins can do many things apart from just being a Continuous Integration server. Originally known as Hudson, Jenkins is an open-source project written by Kohsuke Kawaguchi. As Jenkins is a Java-based project, before installing and running Jenkins on your machine, you need to install Java 8.

The Multibranch Pipeline allows you to automatically create a pipeline for each branch on your Source Code Management (SCM) repository with the help of Jenkinsfile.

What Is a Jenkinsfile?

Jenkins pipelines can be defined using a text file called Jenkinsfile. You can implement pipeline as code using Jenkinsfile, and this can be defined by using a domain-specific language (DSL). With Jenkinsfile, you can write the steps needed for running a Jenkins pipeline.

You may also enjoy: Building a Continuous Delivery Pipeline Using Jenkins

What Is a Multi-Branch Pipeline?

The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages, and executes Pipelines for branches that contain an in-source control.

Multi-branch pipeline architecture branching out into master branch and feature branches

Architecture Diagram

5 Steps To Create a Multibranch Pipeline Project

  1. Open the Jenkins homepage in the local environment (such as http://localhost:8080). Click New Item in the top left corner of the Jenkins dashboard.
    Jenkins homepage menu with 'new item' selected
    New item
  2. Enter the name of your project in the Enter an item name field, scroll down, select Multibranch Pipeline, and click the OK button.
    Selection of Multibranch pipeline in project settings
    Multibranch pipeline
  3. In the configure page, we need to configure the GitHub repo source. Scroll down to the Branch sources and select the source from the Add Source dropdown. We will be using GitHub in this demonstration example, so select GitHub from the dropdown.
  4.  Enter the location of the repository using the following steps:
    • Select the Add button to add credentials and click Jenkins. 
    • Enter the GitHub username, Password, ID, and Description
    • Select dropdown to add credentials in the credentials field.
    • Click the Save button.
      Steps of entering repository location in branch sources
      Branch sources 
  5. On saving, Jenkins automatically scans the designated repository and does some indexing for organization folders. Organization folders enable Jenkins to monitor an entire GitHub Organization or Bitbucket Team/Project and automatically create new Multibranch Pipelines for repositories that contain branches and pull requests containing a Jenkins file.
    Scan repository log
    Scan repository log

Currently, this functionality exists only for GitHub and Bitbucket, with functionality provided by the GitHub Organization Folder and Bitbucket Branch Source plugins. Once jobs are created, the build gets triggered automatically.

database of builds triggered

Builds triggered

Configuring Webhooks for Multibranch Pipeline Project

In the next step, we have to configure our Jenkins machine to make it able to communicate with our GitHub repository. For that, we need to get the Hook URL of the Jenkins machine. Mentioned below are the steps to set up Jenkins webhooks on the GitHub repo.

  1. Go to Manage Jenkins and select the Configure System view. 
  2. Find the GitHub Plugin Configuration section and click on the Advanced button. 
  3. Select the Specify another hook URL for GitHub configuration. Copy the URL in the text box field and unselect it. Then click on Save.  It will redirect to the Jenkins dashboard.selection of specify another hook URL for GitHub configuration
     Webhooks
  4. Now navigate to the GitHub tab on the browser and select your GitHub repository. 
  5. Click on Settings. It will navigate to the repository settings.Settings
     Settings
  6. Under the Settings, click on the Webhooks option and then click on the Add Webhook button. Paste the Hook URL on the Payload URL field. Make sure the trigger webhook field has Just the push event option selected.Steps for adding the webhook
     Add webhook
  7. Click Add webhook and it will add the webhook to your repository. Once you've added a webhook correctly, you can see the webhook with a green tick as depicted in the following image.Webhook added confirmation
     Added webhook
  8. Now go back to the repository, change the branch, and update any of the files. In this scenario, we will update the README.md file. In the image below, we can see that the Jenkins job is getting triggered automatically. changing the branch and updating files through CI triggers
    CI Triggers
  9. After pipeline execution is completed, we can verify the history of the executed build under the Build History by clicking the build number. On clicking the build number, select Console Output. From there, you can see the outputs in each step.verifying the history of the executed build in Console Output
     Console output

Conclusion

With this, we have learned the process of creating a Jenkins multibranch pipeline project and configuring it with the Git repo. You saw how easy it is to create a multibranch pipeline project where Jenkins creates a new independent job automatically every time you create a new branch. Jenkins even takes care of branch maintenance, it can remove the job automatically when you remove the branch. Hope you found this article useful. 

Further Reading

  • How To Build an Effective CI/CD Pipeline: Practical Steps for Creating Pipelines That Accelerate Deployments
Continuous Integration/Deployment Jenkins (software) Pipeline (software)

Opinions expressed by DZone contributors are their own.

Related

  • Implementing CI/CD Pipelines With Jenkins and Docker
  • Getting Started With Jenkins
  • Autonomous Pipelines: Transforming CI/CD With Full Automation
  • Rethinking the Software Supply Chain for Agents

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook