Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

Jenkins – How to build a specific branch on GitHub

by Cloudbooklet
4 years ago
in Google Cloud, Compute Engine
Jenkins - How To Build A Specific Branch On Github
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Jenkins – How to build a specific branch on GitHub. In this guide you are going to learn how to configure Jenkins to trigger build automatically once a change is made to a specific branch in GitHub. By default if you configure CI/CD using Jenkins to build automatically once a commit is made, it triggers […]

ADVERTISEMENT

Jenkins – How to build a specific branch on GitHub. In this guide you are going to learn how to configure Jenkins to trigger build automatically once a change is made to a specific branch in GitHub.

By default if you configure CI/CD using Jenkins to build automatically once a commit is made, it triggers the build for commits made to any branch in a repository.

Prerequisites

  • Install and configure Jenkins on Ubuntu.
  • Setup Nginx reverse proxy for your Jenkins Installation.

Make sure you have the above mentioned prerequisites are completed.

ADVERTISEMENT

Step 1: Install Generic Webhooks Trigger Plugin

Login to your Jenkins installation setup and navigate to Manage Jenkins >> Manage Plugins and click on the Available tab and install Generic Webhook Trigger Plugin.

You might also like

How To Setup Ssh Keys On Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

4 months ago
Draggan Ai Editing Tool Install And Use Draggan Photo Editor

DragGAN AI Editing Tool Install and Use DragGAN Photo Editor

4 months ago

Restart Jenkins to use the plugin.

Step 2: Setup GitHub Personal Access Token

Login to your GitHub account and go to your account Settings >> Developer Settings >> Personal access tokens.

ADVERTISEMENT

Click Generate new token.

Enter a note in the Note field.

ADVERTISEMENT

Select repo.

Click Generate token.

ADVERTISEMENT

Now a new token will be visible for this one time.

Copy the generated token.

ADVERTISEMENT
Generate Personal Access Token

Step 3: Setup Webhooks in Github

Login to your GitHub account and go to the repository that is configured in Jenkins. Click on Settings >> Webhooks.

In the Payload URL enter the the url in the following format.

Replace JENKINS_URL with your own URL.

Replace YOUR_TOKEN with the personal access token you created in the previous step.

https://JENKINS_URL/generic-webhook-trigger/invoke?token=YOUR_TOKEN

In the Content type select application/json.

In the Which events choose Just the push event.

Click Add webhook.

Add Webhook In Github

Step 4: Configure Jenkins to build only specific branch

Once you have your Webhook created you can configure Jenkins to trigger build only if a push is made to the specific repository.

This configuration is for Freestyle Project in Jenkins.

Login to your Jenkins installation and go you your job and click configure.

In the Source Code Management section under Build Triggers check the Generic Webhook Trigger.

Click Add next to the Post content parameters.

Once a push is made, GitHub passes the branch name in the JSON format with the ref key.

The example payload will look something as shown below.

{
   "ref": "refs/heads/branch_name",
   "before": "5b6f5bfbb31d9d28f5655cs8753gae308ef392c5",
   "after": "0000000000000000000000000000000000000000",
   "repository": { 

...

In the Variable enter the name of the variable as ref.

In the Expression enter $.ref to match the key and choose the JSONPath format of payload.

In the Token field enter the personal access token you created before.

Next we can configure Optional Filter.

In the Expression field enter the branch name to match the key ref as shown below.

refs/heads/branch_name\srepository

In the Text field enter the variable name you assigned before as $ref $repository .

Save the configuration.

Jenkins Build A Specific Branch On Github

Now you have configured your job to trigger the build only a push is made to a specific branch.

Gain a skill set to cultivate a Continuous Integration and Continuous Deployment capability now

Conclusion

Now you have learned how to configure Jenkins to trigger build automatically if a push is made to the specific branch.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Tags: Google Cloud PlatformJenkins
Share10Tweet6SendShare
Cloudbooklet

Cloudbooklet

Comments 4

  1. Avatar Of Senthilnathan Senthilnathan says:
    8 months ago

    Working flawlessly. You saved a day for me.

    Reply
    • Avatar Of Cloudbooklet Cloudbooklet says:
      8 months ago

      Great, thank you.

      Reply
  2. Avatar Of Jeevesh Tiwari Jeevesh Tiwari says:
    1 year ago

    Hi,

    I am using the above given steps, but still its triggering for all branches not to specific branch.
    any suggestion please.

    Reply
    • Avatar Of Marty Marty says:
      6 months ago

      I am having same issue. I have webhooks set up on 3 branches, each with unique tokens, linked to 3 jobs. They all use the same jenkinsfile with conditional statements. Pushing to 1 branch triggers all 3 jobs. Anyone know how to resole this? Thanks

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Set Up Deep Learning With Nvidia, Cuda, Cudnn On Ubuntu

How to Set Up Deep Learning with Nvidia, CUDA, cuDNN on Ubuntu 22.04

7 months ago
How To Install Or Upgrade Php 8.2 On Ubuntu 22.04

How to Install or Upgrade PHP 8.2 on Ubuntu 22.04

9 months ago
How To Change Timezone On Ubuntu 22.04

How to Change Timezone on Ubuntu 22.04

1 year ago
How To Install Ansible On Ubuntu 22.04

How to Install Ansible on Ubuntu 22.04

1 year ago

Follow Us

Trending Articles

Ai Comic Generator

Best 10 AI Comic Generator: Create Comic book in Seconds

September 18, 2023

10 Best AI Prompts for Writers to Improve Website SEO

5 Free AI Soulmate Maker: Create Your Perfect Match

Top 7 Free Dating Sites for Men in 2023

HeyGen AI: Free AI Video Generator to Create Amazing Videos

Amazon Prime Big Deal Days 2023: Best Deals

Popular Articles

Stable Diffusion For Free

3 Ways to Use Stable Diffusion AI Art Generator for Free

August 24, 2023

How to Find Songs on YouTube by Humming the Tune

Top 5 AI Jewellery Generators to Create Jewellery Designs

Jenni AI: How to Use AI Writing Assistant for Amazing Content

Quantum AI Trading: The Future of Trading

Top 10 Advantages of a Cloud VPS Server

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.