How can I make Jenkins CI with Git trigger on pushes to master?

0 votes
I want Jenkins to run build scripts only whenever someone on the project pushes to master.
Aug 13, 2018 in Jenkins by Hannah
• 16,210 points
225 views

3 answers to this question.

0 votes
  • Set the Jenkins job's build trigger to Poll SCM, but do not specify a schedule.
  • Create a GitHub post-receive trigger to notify the URL
  • http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>?token=<get token from git to build remotely>
  • This will trigger all builds that poll the specified Git repository.
  • However, polling actually checks whether anything has been pushed to the used branch.
answered Aug 13, 2018 by Kalgi
• 41,990 points
0 votes

Generic webhook trigger can be useful

When configured with

  • A variable named ref and expression $.ref.
  • A filter with text $ref and filter expression like ^(refs/heads/feature/.+)$.

Then that job will trigger for every push to master. No polling.

answered Aug 13, 2018 by lina
• 8,110 points
0 votes

To automatically run build on code commit, follow these steps:

  1. Configuring Jenkins: 
    Jenkins listens for POST requests at a Hook URL. We need to give this URL to the repository on GitHub. Then, whenever code is pushed to that repository, GitHub will send a POST request to the Hook URL and Jenkins will run the build.

    • To get the Hook URL of Jenkins, Open the Jenkins Dashboard.

    • Go to: Manage Jenkins > Configure System

    • Under GitHub Plugin Configuration, Click on ‘Advanced' tab. 

    • Check 'Specify another hook url' for GitHub configuration. 

    • A textbox will appear with a hook URL. This is the Hook URL at which Jenkins will listen for POST requests. Copy this URL and go to the next step.

  2. Configuring GitHub Repository: 
    We now have to provide the Hook URL we got from Jenkins in the previous step.

    • Open your repository on GitHub.

    • Click ‘Settings’ on the navigation bar on the right-hand side of the screen.

    • Click ‘Webhooks ’ on the navigation bar on the left-hand side of the screen.

    • Click ‘Add webhook’ to add the webhook. 

    • Paste the URL you copied in the previous step as the ‘Payload URL’.

    • You can select the events for which you want the Jenkins build to be triggered. We will select ‘Just the push event’ because we want to run the build when we push our code to the repository.

    • Click ‘Add webhook’. 

    • You should now see the webhook you just added in the list of Webhooks for that repository.

  3. Configuring Jenkins Project : We now have Jenkins configured to run builds automatically when code is pushed to central repositories. However, Jenkins doesn’t run all builds for all projects. To specify which project builds need to run, we have to modify the project configuration.

    • In Jenkins, go to the project configuration of the project for which you want to run an automated build.

    • In the ‘Build Triggers’ section, select 'Github hook trigger for GITScm Polling'. 

    • Save your project.

Jenkins will now run the build whenever you push/commit your code to the GitHub repository.

answered Aug 7 by Sirajul
• 36,220 points

Related Questions In Jenkins

0 votes
2 answers

How can I point Jenkins to another .jenkins home directory?

Here are the options you have: a) Assuming ...READ MORE

answered Aug 7 in Jenkins by Sirajul
• 36,220 points
358 views
0 votes
1 answer

I’m facing a login error when I try to run Jenkins on Docker. How do I solve this?

You have to open the /var/log/jenkins/jenkins.log file to ...READ MORE

answered Jul 24, 2018 in Jenkins by Sophie may
• 9,850 points
310 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
206 views
0 votes
1 answer
0 votes
1 answer

How to serve Jenkins with Caddy?

Using the transparent preset fixes this: jenkins.example.com { ...READ MORE

answered Aug 8, 2018 in Jenkins by Kalgi
• 41,990 points
84 views
+5 votes
4 answers

How can I run a Jenkinsfile from a particular folder?

Consider the below points: The Freestyle project ...READ MORE

answered Mar 26, 2018 in Jenkins by anonymous
4,224 views