how to do i run on slave when changes are made to master and run on slave when changes are made on anyother branch.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
Using Git hooks with Jenkins for CI/CD is a common practice and can be accomplished using a variety of methods. However, Jenkins typically uses webhooks, not Git hooks, to trigger builds. Here’s how you can set it up:
You’ll want to have a separate Jenkins job for the master branch and for the other branches. You can use Jenkins’ Multibranch Pipeline to automatically create a pipeline for each branch in your repository.
This process might vary slightly depending on where your Git repository is hosted (like GitHub, GitLab, Bitbucket, etc.). Generally, you’ll go to the settings for your repository, find the webhooks section, and add a new webhook. The Payload URL will be your Jenkins server URL followed by /github-webhook/ or /gitlab-webhook/ etc., depending on your Git host.
For GitHub, for example, it would be http://your-jenkins-server/github-webhook/.
In the configuration for each Jenkins job, you will need to set up the job to be triggered by the corresponding webhook.
In a Pipeline job, you’d add this to your Jenkinsfile:
triggers {
githubPush()
}
Or, in a freestyle job or similar, you’d check the box for GitHub hook trigger (or similar, depending on your Git host) in the job configuration.
In your Jenkins master node, you will need to go to “Manage Nodes” and set up your slave nodes. This involves giving each one a unique name and setting up how the master will connect to the slave.
In the Jenkins job configuration, you’ll have an option to restrict where the job can be run. You can use the “Restrict where this project can be run” checkbox and then specify the name of the slave where the job should run.
You can differentiate between branches in your Jenkins job using the env.BRANCH_NAME variable. In a Pipeline job, you could do this in your Jenkinsfile:
if (env.BRANCH_NAME == 'master') {
// run steps for when changes are made to master
} else {
// run steps for when changes are made to any other branch
}
In this way, when changes are pushed to the Git repository, the corresponding webhook will trigger the appropriate Jenkins job. The Jenkins job will then run on the specified slave node.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.